From the mind of Jamie Huskisson: Nottingham freelance UK PHP, Magento, Wordpress developer

Adding GZIP Compression To Your Site Via .htaccess

Posted on April 17th, 2005 in ,

Just thought i’d post this little tidbit of code for you. Paste it into your .htaccess file and it will enable GZIP across all pages in that directory:

php_value output_handler ob_gzhandler

Hows it do it?

This line of code sets the output handler, or output buffer as ob_gzhandler. This sets the ob_start as “ob_gzhandler” so the code doesn’t have to be entered. Normally you would have to enter this in the PHP to do GZIP Compression:

// In the head:
ob_start(“ob_gzhandler”);
// At the bottom:
ob_end_flush();

What is GZIP?

GZIP is a very> effective way of keeping your bandwidth down when having large HTML/PHP pages. What it does, is compresses the page thats being sent to the user viewing your site, when the user recieves this compressed version of the page it uncompresses the page, and views it in the full form.

But how much does this effect the user?

It doesn’t effect the user at all, except for Internet Explorer 0.01 users still on Windows 3.11 of course…

And what about my server?

Once you originally implement this, yes, you will notice changes in your processors activity. But after a day or two you’ll soon see the processor levels lower.

How much of a difference does it really make?

The answer, is roughly 80-90% of your raw code file being sent to the user is removed.

A good implementation case study for this is Pixel2Life. Before GZIP it had a 160kb file output and after a 14kb file output. This of course is brilliant for the 56kers, which alot of us forget about.

Please note

GZIP does not compress images, just the raw code being output and sent to the user.

Bookmark and Share

If you enjoyed this post:

Please take the time to leave a comment with any of your thoughts, follow me on Twitter or subscribe to my RSS Feed for automatic updates on all future posts.

There are 30 responses to this post so far

Feel free to use any of the following tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>