Second step is to enable automatic compression. Well that's pretty easy too.
I'm using Apache on Linux. Usually the Apache module: mod_deflate will be enabled by default. If not you have to enable it like this:
$ a2enmod deflate
$ /etc/init.d/apache2 force-reload
Instructing Apache What to Compress
Next we need to tell the webserver what file types need to be deflated. This can be done by either:
- creating an
.htaccessfile in your webroot, OR:
- modifying your VHost
Some people argue that configuration in the VHost is better because it saves your server the disk IO of accessing the .htaccess file with every request. But for VHost configuration you will need to be admin of your server, and an .htaccess file is as easy as uploading one with FTP. You choose.
Enter the following lines in one of the above files. And why not compress/deflate HTML, XML & CSS while we're at it?
# Compress Output
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
The browser specific exceptions are necessary for compatibility.
Save the file, optionally (in the case of vhost) reload the apache config, and your files are now compressed on the fly! Do you notice the difference?