I’m slowly working my way down my website todo list, and today came to the topic of webpage compression. Webpage compression, when done right, is a robust solution to decreasing the size of your pages and hence speeding up page load times, all whilst coping with older browser types. Thanks go to posts at “Textism(Textism – Bigsmallbig – 21 November 02)”:http://www.textism.com/article/632/ and “Mark Pilgrim(Mark Pilgrim – A warning to others)”:http://diveintomark.org/archives/2002/11/21/a_warning_to_others for putting this on my radar in the first place.

The conventional approach to compressing your webpages is to use “mod_gzip”:http://sourceforge.net/projects/mod-gzip/. This module is run by Apache after all other modules have run – so it will work on dynamic content. Firstly, it determines if the client can understand gziped content – if it can it the webpage is compressed, otherwise the normal page is sent. This does require you have mod_gzip installed however and you have to associate the correct mine with the module. An excellent overview of mod_gzip can be found at “Web Compression(Compressing Web Output Using mod_gzip for Apache 1.3.x and 2.0.x)”:http://webcompression.org/gzip-compress.html, which is an excellent resource on the topic of website compression as a whole.

Another approach is to use PHP’s “ob_start”:http://uk2.php.net/ob_start function buffering. Simply by inserting :

at the top of each HTML file PHP performs the same job as mod_gzip – checking the client can understand compressed content before performing the compression. The advantage of this is that assuming your host has PHP 4.0.4 or better it will work – no configuration is required by your host. The downside is that you need to add the code to the top of each file. Given that I have a great deal of control over my page generation due to Movable Type I went for this approach.

If you have the misfortune to be running on a host without either Apache or PHP, but are fortunate enough to be running a Servlet engine (an unlikely set of circumstances though it might be) you could always write a filter to perform the compression. The OnJava article “Two Servlet Filters Every Web Application Should Have(OnJava.com – Two Servlet Filters Every Web Application Should Have [Nov. 19,2003])”:http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html by Jayson Falkner details one such filter.

Once you’ve compressed your output, head over to a resource like the “Web Page Analyzer”:http://www.websiteoptimization.com/services/analyze/ and see how fast your site is now. Next on my todo list: moving to XHTML 1.0 Strict…