Enabling GZip Encoding On IIS7

Posted By : todd sharp Posted At : June 10, 2009 9:30 AM Posted In: JavaScript, CSS, ColdFusion

6

I've spent a bit of time lately trying to figure out how to enable GZip compression on IIS7. I don't have much experience with GZip, but it doesn't take a rocket scientist to figure out that a smaller file results in a faster page download which always ends in a happier user.

So most of the early advice I found for enabling GZip involved modifying your 'web.config' file. Well, that's all well and good if you're using ASP and actually have a web.config file. Since I'm not using ASP that didn't work out so well for me.

Then I found this post which explained how to use Appcmd.exe to enable dynamic compression. Feel free to read those articles, but here's the quick version:

Step 1: Open a command prompt with elevated permissions.

Step 2: Enter the following command:

C:\Windows\System32\Inetsrv\Appcmd.exe set config -section:urlCompression -doStaticCompression:true -doDynamicCompression:true

Note: This enables dynamic compression at the server level. The following command supposedly enables it at the site level, but that failed in my tests:

C:\Windows\System32\Inetsrv\Appcmd.exe set config "Site Name" -section:urlCompression -doStaticCompression:true -doDynamicCompression:true

I restarted the WWW Publishing service for good measure, cleared my browser cache and hit a few pages with a fair amount of JavaScript/CSS files and checked Fiddler. Sure enough the requests confirmed GZip encoding. A peak in Firebug showed the core jQuery library went from 56KB down to 17KB. My CSS file went from 15KB to just over 4KB. Now those are performance enhancements any developer could love!

I do suggest you do a bit more research to make sure this solution doesn't have any negative side effects for your particular setup. This post seems to go into serious detail on the pros/cons.

Comments (6)

Roland Collins's Gravatar If you have the compression feature turned on in the IIS section of the Windows add/remove features dialog, you should get a nice litlle Compression applet in the IIS Manager. Makes it even easier :)

Also, be aware that enabling compression on dynamic content will disable cfflush entirely.

todd sharp's Gravatar @Roland: Very cool. That does help, thanks! Of course it had to be something that's not enabled by default.

And thanks for the heads up on cfflush - I don't use it much, but it's good to let people know.

Sami Hoda's Gravatar Yeah, I thought it was as simple as 1-2-3 with the GUI. You definitely want to use that.

Dan Vega's Gravatar Does the GUI only work in 7? I am in Add/Remove Windows Components and I can't find anything.

John Whish's Gravatar @Dan, for IIS 6 you need to use the command line. I blogged this a while back:
http://www.aliaspooryorik.com/blog/index.cfm/e/pos...

kelebek's Gravatar thank you