tags:

views:

7398

answers:

8
+16  Q: 

Enable IIS7 gzip

How can I enable IIS7 to gzip static files like js and css and how can I test if IIS7 is really gziping them before sending to the client?

Thanks!

+2  A: 

Here's a nice post on the topic..

http://www.coderjournal.com/2008/04/iis-7-compress-javascript-gzip/

madcolor
This article helped me, though I think it's worth pointing out that the httpCompression settings appear to be quite different between IIS7.0 and IIS7.5. As a result, compression of .js files appears to work out-of-the-box with IIS7.5.
Gavin Schultz-Ohkubo
+10  A: 
Gulzar
+1  A: 

This explains compression in IIS7 : http://blogs.iis.net/ksingla/archive/2006/06/13/changes-to-compression-in-iis7.aspx

..and for testing, I find Safari's Network Timeline tool gives nicely displayed info about what the browser is receiving from the server. It will actually show warnings/hints telling you if you are not using compression.

markt
+5  A: 

Global Gzip in HttpModule

If you don't have access to the final IIS instance (shared hosting...) you can create a HttpModule that adds this code to every HttpApplication.Begin_Request event :

HttpContext context = HttpContext.Current;
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip");
HttpContext.Current.Response.Cache.VaryByHeaders["Accept-encoding"] = true;

Testing

Kudos, no solution is done without testing. I like to use the Firefox plugin "Liveheaders" it shows all the information about every http message between the browser and server, including compression, file size (which you could compare to the file size on the server).

rizzle
About to try this out!
Maxim Zaslavsky
+1  A: 

If you use YSlow with Firebug and analyse your page performance, YSlow will certainly tell you what artifacts on your page are not gzip'd!

jadusty
+1  A: 

Another really nice tool from google is Page Speed with Firebug http://code.google.com/speed/page-speed/

Patrik Potocki
A: 

I think you might find this article interesting as it covers GZipping static content:

Creating Static Content Website in IIS 7

Lucifer