PDA

View Full Version : How to implement GZIP using PHP



manugoel2003
19 Dec 2006, 11:39 PM
Hi,

I am trying to implement Gzipping. I am using PHP as a backend and cross-browser support is a must. But I have a few queries.

1. Is it a good idea to Gzip all the JS & CSS or should only JS be Gzipped. And what all files can be Gzipped.
2. Is it possible to use Gzipping on HTML as well :)
3. I hope all this can be done in PHP only, coz I dont know any other server-side technology.
4. And is all this done on-the-fly transparently at the client end, or do I have to do geeky coding for it.
5. And lastly, How do I actually go about doing it? :D


Thanx
Manu

manugoel2003
19 Dec 2006, 11:43 PM
And ya, I forgot to mention that I have already followed some advice from the following article, but it didnt help.

http://www.fiftyfoureleven.com/sandbox/weblog/2004/jun/the-definitive-css-gzip-method

Animal
20 Dec 2006, 12:07 AM
This has been discussed. I posted a solution for J2EE developers.

http://www.yui-ext.com/forum/viewtopic.php?t=1304#5550

manugoel2003
20 Dec 2006, 4:41 AM
Ya I already read that post, but as it is for J2EE developers I cannot understand it very well, much less implement it. A PHP based solution would be a great help.

moraes
20 Dec 2006, 5:05 AM
Some links of interest:

http://www.dustindiaz.com/yahoo-event-utility/
http://www.ilovejackdaniels.com/php/php-gzip-and-htaccess/

I'm interested in a solution specific for YUI-ext, but I'll be back to this subject after I advance a little more on my app.

Animal
20 Dec 2006, 7:10 AM
How about this: http://rakaz.nl/projects/combine/combine.phps

manugoel2003
20 Dec 2006, 10:23 AM
Thanx a lot for the replies.... I'll go through them and see if anything works out... btw, which method is better - Zlib or the Output Buffer if I am using Zend Framework and using its rewrite engine??....

Slapyo
20 Dec 2006, 10:37 AM
http://www.yui-ext.com/forum/viewtopic.php?t=1669

I just posted about gzipping css and js files, didn't see this thread ... and sadly I forgot to search prior to making my post. But searched google and found the link that manugoel2003 provided in the second post. It helped me out a bunch.

manugoel2003
20 Dec 2006, 11:01 PM
hey guys this script is working for CSS files


<?php
ob_start ("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>


and there is a corresponding version for JS as well


<?php
ob_start ("ob_gzhandler");
header("Content-type: application/x-javascript; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>


Thank u all for ur help.... but I was not able to make the auto-prepend work in htaccess file.... I am using this code in my htaccesss file


AddHandler application/x-httpd-php .css
php_value auto_prepend_file gzip-css.php


Any idea what may be wrong in this??

And what tools can I use for monitoring file-size and other such details in IE and Firefox.... I am currently using Firebug which does not give any details on the filesize and gzipping... I would like to monitor both the AJAX response sizes and the file sizes


Thanx all


Manu
manu@value-one.com
www.e11online.com

Animal
21 Dec 2006, 12:22 AM
Get the latest Firebug from http://getfirebug.com/

You can monitor the size and time of every HTTP request.

wolverine4277
3 Aug 2007, 1:10 PM
This link can help you:

http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files