HTTP Compression in IIS

When bandwidth becomes an issue, it is possible to enable HTTP compression between the web server and the browser. This increases CPU load on the web server by a small amount, but can provide fairly massive reductions in page sizes (in the order of 75%).

Compression is part of the HTTP/1.1 specification, which means that most browsers since 1999 support it. In the rare cases where a browser doesn't support the technique, the server will discover this in the initial HTTP handshake and deliver uncompressed pages instead.

To enable HTTP compression for your IIS webserver, changes are made to the IIS server settings. Note that while this will require a restart of IIS, it shouldn't require CF to be restarted.

  1. Open the IIS Manager
  2. Expand the SERVERNAME section
  3. Right click on the Web Sites section and choose Properties from the menu
  4. Go to the Service tab
  5. Check Compress Application Files
  6. Check Compress Static Files
  7. Change Maximum Temporary Folder Size to 100MB (just to be safe)
  8. Hit OK

This has enabled HTTP Compression, but only Microsoft's default file types. We want to add a couple extra static types (CSS and JS) and one very important application type (CFM), which is done through the IIS metabase.

Open a command window Change directory to c:\inetpub\Adminscripts\ Type the following lines (or copy and paste):

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "css" js"
cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "
htm" "html" "txt" "css" "js"

Next we want to add support for CFM application file types, with these lines

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "cfm"
cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "cfm"

Finally we apply these changes by restarting the IIS service

IISreset.exe /restart

Close the command window

To check that the changes have been successful, I use the Web Developer addon for Mozilla. The menu option to use is:

Web Developer -> Information -> View Document Size

This will show both the compressed and uncompressed sizes of all the elements on a particular page. Note that you may need to clear your cache to have the browser reload the compressed page elements if the old, uncompressed elements are present.

CFHTTP Problems

Unfortunately, there is a problem that occurs with compressed pages on IIS and cfhttp calls. IIS's compression scheme is incompatible with CF and will result in a "Connection Failure" error. To fix this, we add these extra parameters to the cfhttp call, to let the server know that it shouldn't use compression.

<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">

References

http://www.http-compression.com

http://www.eggheadcafe.com/articles/20020716.asp

http://www.talkingtree.com/blog/index.cfm/2004/7/28/20040729

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Richard Davies's Gravatar Thanks for this great information! I didn't realize that IIS supported gzip compression out of the box.
# Posted By Richard Davies | 20/09/07 08:42
Shawn Becker's Gravatar Thanks for this straight forward guide, I looked all over for this, and this one worked first try. I just host on my personal internet connection, so really don't have a lot of bandwidth. Anyway, worked good. Thanks.
# Posted By Shawn Becker | 06/06/08 15:47
jmoss's Gravatar You don't need the additional httpparams if you only enable GZIP in IIS.
# Posted By jmoss | 16/07/08 01:34
Francis's Gravatar Hey guys, I would recommend checking out httpZip and ZipEnable (www.Port80Software.com).

These 2 products are well, worth the price and have much more functionality than native-compression.

If anyone has any questions pertaining to either one, feel free to contact me.

Thanks!

Andrew
# Posted By Francis | 31/01/09 06:41
wow gold's Gravatar This will show both the compressed and uncompressed sizes of all the elements on a particular page.
# Posted By wow gold | 27/06/09 14:49
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001.