Turning on mod_deflate to speed up apache

May 20, 2009

When doing some performance tuning for iformis I have noticed a lot of HTTP overhead in serving pages in modern web applications. This is often due to image heavy designs, large javascript libraries and since the average connection speed of clients has increased, asset number and size are being pushed to the background.

By default apache does not perform gzip compression. I recently turned this on and along with a small increase in load I noticed a large performance increase from the client side.

To turn it on (debian / ubuntu)

sudo a2enmod deflate

Now im not a fan of copy and paste configs but included below is the mod_deflate config I am currently using. At least read it before using. (Doesnt gzip certain file type and turns off some gzipping for older browsers.)

SetOutputFilter DEFLATE
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
      no-gzip dont-vary
  SetEnvIfNoCase Request_URI \
      \.(?:exe|t?gz|zip|bz2|sit|rar)$ \
      no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html