views:

2022

answers:

2

I have an ASP.NET webforms application (3.5 SP1) that I'm working on, and attempting to enable gzip fpr HTML and CSS that comes down the pipe. I'm using this implementation (and tried a few others that hook into Application_BeginRequest), and it seems to be corrupting the external CSS file that the pages use, but intermittently...suddenly all styles will disappear on a page refresh, stay that way for awhile, and then suddenly start working again.

Both IE7 and FF3 exhibit this behavior. When viewing the CSS using the web developer toolbar, it returns jibberish. The cache-control header is coming through as "private," but I don't know enough to figure out if that's a contributing factor or not.

Also, this is running on the ASP.NET Development Server. Maybe it'd be fine with IIS, but I'm developing on XP and it'd be IIS5.

A: 

If you will be deploying on IIS 6 or IIS 7, just use the built-in IIS compression. We're using it on production sites for compressing HTML, CSS, and JavaScript with no errors. It also caches the compressed version on the server, so the compression hit is only taken once.

Sean Carpenter
Unfortunatly, using the default settings seems to break zip files in IE7/8. As it turns out, by default IIS wants to try compressing zip files, which is rather silly.
Cory R. King
+5  A: 

Is it only CSS files that get corrupted? Do JS files (or any other static text files) come through ok?

Also can you duplicate the behavior if you browse directly to the CSS file?

I've only enabled compression on Windows 2003 server's IIS using this approach:

  1. IIS → Web Sites → Properties → Service tab, check both boxes
  2. IIS → Web Service Extensions → Right click, Add New
      Name
          Http Compression 
      Required Files
          %systemroot%\system32\inetsrv\gzip.dll 
  3. IIS → Right click top node, Internet Information Services, check Enable Direct Metabase Edit
  4. Backup and Edit %systemroot%\system32\inetsrv\MetaBase.xml
    1. Find Location ="/LM/W3SVC/Filters/Compression/gzip"
    2. Add png, css, js and any other static file extensions to HcFileExtensions
    3. Add aspx and any other executable extensions to HcScriptFileExtensions
    4. Save
  5. Restart IIS (run iisreset)

If you have a Windows 2003/2008 server to play with you could try that approach.

travis
fixed my problem, thanks!!
craigmoliver
IE7/8 was downloading corrupt zip files while Firefox/Chrome/Opera was not. This seemed to be because IIS6 was gzip compressing the zip file, which would upset IE. Your solution fixed my problem and IIS no longer tries to re-compress compressed files.
Cory R. King