Andrew Connell

Limiting the Page Payload with IIS HTTP Compression

This past week I presented a session at TechEd EMEA that covered various things you want to do before launching your anonymous, Internet-facing MOSS 2007 (WCM) Publishing site (session OFC309). One of the topics I addressed was striving for the smallest page payload for requested pages. The page payload is the combined total size of all files required for a page request which includes all HTML markup, images, JavaScript, CSS and other assets on referenced in the markup. The best way to address the page payload is doing what you can to make all the files as small as you possibly can including doing things such as implementing a CSS-based (pixel perfect) design instead of one that is table-based.

There’s another option, as I showed in the session: IIS HTTP compression. IIS has the capability of compressing, on the fly, static (HTM, HTML, CSS) files as well as dynamic files (ASPX, AXD). By simply turning HTTP compression on, your payload will shrink a bit… in the case of the session demo, it shank by roughly 21%, with no changes to the site codebase or SharePoint itself! Check it out for yourself… below on the left is a screenshot of Fiddler at an OOTB Publishing Portal site and on the right you see the results of the changes I’ve made below (this was done on IIS v7):

Image from remote site

Publishing Portal OOTB configuration

Image from remote site

Publishing Portal after bumping the compression level up to 9

By default, HTTP compression is turned off but when SharePoint provisions a web application, it enables both static and dynamic compression. HTTP compression differs a bit from IIS v6 (Windows 2003) and IIS v7 (Windows 2008).

Know that HTTP compression is a CPU intensive process so the higher the level, the more your CPU is going to be stressed. Both IIS v6 and IIS v7 allow you to set the compression level, a scale of 0-10 with 10 being the highest compression level. I’d recommend you push it as high as you can without negatively affecting the performance of the overall web server.

HTTP Compression in IIS v6 (Windows 2003)

First, you need to add a few static files to the list of static & dynamic file types by entering the following commands:

  • Add HTM, HTML, TXT, CSS and JS files to static compression:

    CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcFileExtensions
      "htm" "html" "txt" "css" "js"
    CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcFileExtensions
      "htm" "html" "txt" "css" "js"
  • Add ASP, EXE, ASPX and AXD files to dynamic compression:

    CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions
      "asp" "exe" "axd" "aspx"
    CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions
      "asp" "exe" "axd" "aspx"

Next, you can configure the compression level. Static is already set to 10, but you can bump up the dynamic as high as your server can handle… the following bumps it up to 9:

  W3Svc/Filters/Compression/DEFLATE/HcDynamicCompressionLevel "9"
  W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel "9"

HTTP Compression in IIS v7 (Windows 2008)

In IIS v6 HTTP compression is configured on a file type by file type using the file type extension whereas in IIS v7 it’s configured using MIME types. IIS v7 also adds some additional capabilities such as allowing the generated HTML markup from ASP.NET to be compressed before being added to the page output cache & also to dynamically set when compression is switched on/off based on how stressed the CPU is.

Thankfully the MIME types we’re interested in area already configured so there’s nothing for us to add there like we had to in IIS v6.

  • To set the compression level, open the C:\Windows\System32\inetsrv\config\applicationHost.config file and jump to the section (around line 574). Add the dynamicCompressionLevel attribute to the node like this:

  • Next, tell IIS v7 to add compressed pages to the ASP.NET page output cache instead of deferring the caching until the request pulls it from cache:

    APPCMD.EXE set config -section:httpCompression
    APPCMD.EXE set config -section:httpCompression
  • Finally, configure IIS v7 to dynamically turn caching on/off based on the utilization of the server… below I’m telling it to only compress when the CPU utilization is between 20-75%:

    APPCMD.EXE set config -section:urlCompression

Take one last thing into consideration: your mileage may vary. What I mean by this is that *every* environment, site and usage is different. The settings I list here may or may not work for you. Like any performance optimization process, you need to adjust the tuning knobs, test and analyze the results to find what works best for your environment. I’m using a compression level of 9 simply to show how much it can help you. I’ve heard some say don’t go above 4… personally I don’t see why you shouldn’t go as high as you can as long as the CPU can handle it. So again… your mileage may vary.

Happy caching!

Andrew Connell
Founder & Chief Course Artisan, Voitanos LLC. | Microsoft MVP
Written by Andrew Connell

Andrew Connell is a web developer with a focus on Microsoft Azure & Microsoft 365. He’s received Microsoft’s MVP award every year since 2005 and has helped thousands of developers through the various courses he’s authored & taught. Andrew’s the founder of Voitanos and is dedicated to delivering industry-leading on-demand video training to professional developers. He lives with his wife & two kids in Florida.