How to waste bandwidth with mod_gzip

While watching some web access logs recently, I noticed that Internet Explorer was not properly caching images. So for common images shared on all the pages of the server, Internet Explorer was downloading the image over and over again. Firefox was properly caching them, but since the majority of the internet still surfs via IE, this problem was wasting a lot of bandwidth.

After some research, I discovered that this problem was the result of using modgzip on the server. modgzip is an Apache module that compresses web page data before it is sent to the browser, thereby saving bandwidth. You typically only use it on HTML pages since graphics don’t compress well. Even though my modgzip instructions were telling it not to compress images, it was still doing something to the HTTP headers of those files (sending a “Vary” entry). It turns out that this was the cause of IE not caching the images. So my savings in HTML page bandwidth was probably spent in image bandwidth.

I found a solution in <a href=“
gzip/2004-January/007264.html”>this discussion, and it seemed to work for me. I added this to my Apache configuration:

<Files ~ “.(jpg|gif|png)$”>
modgzipsendvary Off

Now I’ll get to see how much bandwidth I can really save with mod

Update 2006-05-07: Lately I’ve been playing around with using PHP to dynamically provide images from a file cache. In that case, to get web caching to work properly, you’ll need to disable the modgzipsend_vary on the PHP filename that generates your images, as the example above only accounts for image filenames.