Getting started with Apache Mod Deflate was fairly simple. Like mod concat from the first piece in the Blog Optimization series, it’s just a matter of compiling and installing mod deflate. Mod deflate comes with Apache 2.2, the first step is locating it.
prompt:$ find / -name mod_deflate.c # change directory (cd) to the location of mod_deflate.c prompt:$ apxs -i -a -c mod_deflate.c prompt:$ apachectl configtest # make sure the syntax is okay prompt:$ apachectl graceful # restart the server
Now that mod_deflate is enabled, it’s time to configure it. I couldn’t find much information during the research phase on configuring the module. I knew from previous experience that I wanted to gzip, or deflate, all static files. Eventually, I found this post on configuring mod_deflate with cPanel. It was helpful, I modified it slightly to include a few other file types
<Location /> AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript application/x-shockwave-flash </Location>
The Apache 2.2 docs indicate the AddOutputFilterByType directive is deprecated and mod_filter should be used instead, I haven’t had time to play around with mod filter and the Apache 2.2 docs urge caution since it’s not fully tested. If anyone has experience with mod filter, please share in the comments section below.
Mod deflate has done wonders to reduce my bandwidth costs and site performance. On average each request uses 25% less bandwidth than without mod_deflate. Obviously images don’t benefit from gzip compression, but all JavaScript, CSS, HTML and flash files are benefiting by being about 50% smaller in size. For instance, JQuery is about 30.3kb on the server. When it’s delivered using mod_deflate it’s 16kb according to Firebug.
Have a look at some before and after numbers from my server logs.
| Day | Number of visits |
Pages | Hits | Bandwidth |
|---|---|---|---|---|
| 26 Dec | 761 | 3966 | 12131 | 242.29 MB |
| 31 Dec | 761 | 4161 | 12809 | 196.94 MB |
Do you have any blog optimization techniques you are using on your site? Check out my related posts on Blog Bloat and using Mod concat if you interested in optimizing your blog or website.