Recently i added some javascript files to my site, and planning to add more later. But the size of these files is pretty big. Because of this i decided to setup mod_deflate.
Mod_deflate in apache2 is pretty much the same as mod_gzip in apache1.3, and mod_deflate is included in apache2 source package. Both modules let to compress the output of Apache server dynamically. Compression can be setup server wide or for some virtual host only. Types of content which need to be compressed can be specified explicitly AddOutputFilterByType and compression level can be specified with DeflateCompressionLevel. Maximum compression level is 9.
To setup compression for some virtual host, one needs to do the following:
$ sudo a2enmod deflate Module deflate installed; run /etc/init.d/apache2 force-reload to enable.
Then add similar lines to the virtual host definition:
<VirtualHost *> ... AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascript DeflateCompressionLevel 9 .. </VirtualHost>
After this apache needs to be restarted. To check if compression works, we can use telnet to connect to web server:
$ telnet localhost 80 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GET / HTTP/1.1 Host: yourhosthere Accept-Encoding: gzip HTTP/1.1 200 OK Date: Fri, 10 Nov 2006 07:10:41 GMT Server: Apache/2.0.55 (Ubuntu) mod_python/3.2.8 Python/2.4.4c1 PHP/4.4.2-1.1 mod_ssl/2.0.55 OpenSSL/0.9.8b Vary: Accept-Encoding Content-Encoding: gzip Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 ....
After that you should see gzip'ed version of your content.