The Power of Compression

Today I was investigating some slowdowns on one of our customer facing sites and after a few minutes working with our developer and Safari, I determined that we weren’t compressing files sent from the server. (Safari warned me in the Show Network Timeline option in the Develop menu.)

As we’re running Apache 2.2.x on Leopard server, I found that it had mod_deflate already installed. While the module was already installed, it wasn’t setup to do anything. After a few minutes reading the documentation and modifying the Apache configuration files, I had compression working. Yeah! Normally I wouldn’t think this would do a lot of good as the connection is pretty fast, but some of the Javascript we use is quite large and compresses quite well. I definitely saw a speed improvement with this simple change.

So my question is, why isn’t there an option in Leopard’s Web Server that says “enable compression”? I see no downside to this using the configuration on the Apache site (Leopard server actually has this enabled for Collaboration) as most modern browser can handle this and can quickly decompress the files.

For reference, I created a file at: /etc/apache2/httpd_deflate.conf that had in it:


<Location />
	# Insert filter
	SetOutputFilter DEFLATE

	# Netscape 4.x has some problems...
	BrowserMatch ^Mozilla/4 gzip-only-text/html

	# Netscape 4.06-4.08 have some more problems
	BrowserMatch ^Mozilla/4\.0[678] no-gzip

	# MSIE masquerades as Netscape, but it is fine
	# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

	# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
	# the above regex won't work. You can use the following
	# workaround to get the desired effect:
	BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

	# Don't compress images
	SetEnvIfNoCase Request_URI \
	\.(?:gif|jpe?g|png)$ no-gzip dont-vary

	# Make sure proxies don't deliver the wrong content
	Header append Vary User-Agent env=!dont-vary
	
</Location>

Then in each site file, I put:

        Include /etc/apache2/httpd_deflate.conf

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.