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!
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!
Here's a nice post on the topic..
http://www.coderjournal.com/2008/04/iis-7-compress-javascript-gzip/
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.
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).
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!
Another really nice tool from google is Page Speed with Firebug http://code.google.com/speed/page-speed/
I think you might find this article interesting as it covers GZipping static content: