Compress your web content for better performance

Most web developers expend a lot of energy optimizing queries, reducing the overhead of functions, and streamlining their application's overall flow. However, many forget that one of the simplest adjustments is the compression of data as it leaves the web server.

Luckily, mod_deflate makes this easy, and the Apache documentation has a handy initial configuration available:

<Location />
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</Location>

This configuration will compress everything except for images. Of course, you can't test this with curl, but you can test it with Firefox and LiveHTTPHeaders. If you don't have Firefox handy, you can try a very handy web application that will give you the statistics about the compression of your site's data.

Printed from: http://rackerhacker.com/2008/09/19/compress-your-web-content-for-better-performance/ .
© Major Hayden 2012.

2 Comments   »

  • I would actually warn *against* the stock configuration that Apache provides, especially seeing that it caters to adjusting gzip content for Netscape 4.x, then re-adjusts to re-fix for MSIE (not sure which version). The end result, if I'm not mistaken, is that you get a Vary User-Agent header attached to every response. If you ever try to use a reverse proxy or CDN for page content this may cause problems.

    While I do compress content, I have removed most of these rules in my own configs. Netscape 4.x is no longer on our radar.

  • Dave says:

    Will this compress flash FLV files?

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this