Compression: the no brainier approach to faster websites
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 and Mark Pilgrim for putting this on my radar in the first place.
The conventional approach to compressing your webpages is to use 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, which is an excellent resource on the topic of website compression as a whole.
Another approach is to use PHP’s ob_start function buffering. Simply by inserting :
<code></code>
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 by Jayson Falkner details one such filter.
Once you’ve compressed your output, head over to a resource like the Web Page Analyzer and see how fast your site is now. Next on my todo list: moving to XHTML 1.0 Strict…
This entry was posted on Thursday, May 6th, 2004 at 1:12 pm and is filed under General. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
Have your say
Fields in bold are required. Email addresses are never published or distributed.
Some HTML code is allowed:
URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.
Line breaks and paragraphs are automatically converted.
Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.