Thu, 22 Apr 2010

IIS Compression in Windows Azure

[UPDATE 9/10/2011] This article is quite out-of-date. With startup tasks and elevated privileges, you can change the compression settings by invoking appcmd. This answer on StackOverflow looks about right to me:

One change you may have noticed in the latest operating system release in Windows Azure is that the dynamic compression module has been turned on in IIS. This means that without doing anything, you should now see the default dynamic compression settings take effect.

Changing the Defaults

Compression settings are primarily controlled by two configuration elements: <urlCompression> and <httpCompression>.

<urlCompression> can be configured at the application level in web.config, and it lets you turn on and off dynamic and static compression. By default, dynamic compression is turned off, so you may want to add the following line to your web.config file (but see the word of caution at the end of this post):

<urlCompression doDynamicCompression="true" dynamicCompressionBeforeCache="true" />

<httpCompression> can only be configured at the level of applicationHost.config, so with today’s web role, you’ll get configuration that looks like the following (though the directory attribute will be different):

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />

Unfortunately, you can’t change applicationHost.config settings in today’s Windows Azure web role. However, you can edit this section in applicationHost.config using the Hosted Web Core Worker Role project.

A Word of Caution

Compression settings are tricky, and adding more compression will not necessarily increase the performance of your application. (Sometimes it will do the exact opposite!) Be sure to do your research first, and then test your new settings to make sure they’re having the effect you expected.