Apache mod_deflate with WordPress

ApacheServerLogo To continue along with my Apache experimentation I decided to enable Apache mod_deflate on my server. All I run is WordPress and I probably won’t gain much of an increase over enabling compression in WP Super Cache. But at least this way I won’t be limited to the plugin and WordPress. I’m running Apache 2 on Ubuntu 8.10 Server and the configuration was a breeze.

Why use compression”? To save bandwidth for myself and visitors, and with less download time it means faster performance.

The /etc/apache2/mods-enabled/deflate.conf file contains the line:

AddOutputFilterByType DEFLATE text/html text/plain text/xml

This compresses text file types but leaves the other alone. I’ll probably add /text/css to compress css files, but for now I’ll keep it simple. This will cover almost everything my site serves except for graphics, which are already compressed.

Older browsers may have a problem with compression even though browsers are supposed to let the server know whether or not they can handle compression. I do have a small number of visitors (about 1/2 of 1%) that report using one of these older browsers so I’ll add an exclusion for them to the configuration. I considered ignoring the issue but since the official documentation had the syntax I used it.

Open the deflate.conf: sudo nano /etc/apache2/mods-available/deflate.conf

Add the three “BrowserMatch” lines to the file so it looks as follows and save it.

<IfModule mod_deflate.c>

          AddOutputFilterByType DEFLATE text/html text/plain text/xml

          BrowserMatch ^Mozilla/4 gzip-only-text/html

          BrowserMatch ^Mozilla/4.0[678] no-gzip

          BrowserMatch bMSIE !no-gzip !gzip-only-text/html

</IfModule>

The only thing left to do was enable mod_deflate by running sudo a2enmod deflate. I can then test the compression at IsMyBlogWorking.com. Compression using mod_deflate was comparable to the results I saw with compression enabled in WP Super Cache (about 72%). It’s working fine with WordPress and compressing the pages being served.

More information about mod_deflate can be found at G-Loaded.