IE6 gzip bug: solved using ISAPI_Rewrite

I’ve recently turned on gzip compression for all static pages on my web server running IIS6, and am now enjoying faster speeds and lower bandwidth.

However, in my investigations I came across a number of bugs in pre-SP2 IE6 (no surprises there) which means that gzipped CSS and Javascript files can be improperly cached and so intermittently mangled.

Not wanting to turn compression off just because of problems with this (thankfully declining) travesty of a browser, I hit on a way of bypassing compression for the affected browsers.

The solution uses ISAPI_Rewrite, which I already used on my server. Simply add the following lines to the global rules file (httpd.conf in your ISAPI_Rewrite installation directory):

RewriteEngine on

RewriteCond %{HTTP:User-Agent} MSIE\ [56]
RewriteCond %{HTTP:User-Agent} !SV1
RewriteCond %{REQUEST_URI} \.(css|js)$
RewriteHeader Accept-Encoding: .* $1

What this does is look at the User-Agent header of any incoming request. If it’s IE5 (just to be safe) or IE6, and the User-Agent doesn’t contain SV1 (which indicates IE6 SP2), and if the requested page is a .css or .js file, then we rewrite the Accept-Encoding header to a blank string (normally it would be gzip/deflate, which indicates that the browser can handle those compression methods).

The end result is that the affected browsers will not claim to handle compression, and so will get uncompressed files; everyone else will receive the benefits of compressed files.

Posted at 1:30 PM on 31 October, 2008, under Miscellaneous, ISAPI_Rewrite

Leave a comment