Asp.net-mvc – Setting IIS7 gzip compression level

asp.net-mvccompressiongzipiisiis-7

In ASP.NET MVC I have used the web.config to enable and configure the IIS7.5 gzip compression settings. But they compress level settings appear to have no effect at all:

<scheme name="gzip" dynamicCompressionLevel="9" staticCompressionLevel="9"/>

With compression level = 0 for both settings, my homepage is gzipped to 9,290 bytes (from 39,623)

With compression level = 9 for both settings, my homepage is gzipped to 9,290 bytes (from 39,623)

(using fiddler to check the zipped/uncompressed sizes)

There is no difference in the amount of compression – why is that? This occurs on my local development machine – Windows 7. I have not tried it on our Win 2008 web server yet.

Full compression settings in web.config:

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

EDIT: apparently the highest level is 9. This page says it is 10 but must be incorrect http://www.iis.net/configreference/system.webserver/httpcompression/scheme. The problem is still the same when using level 9

Best Answer

Please double check you have dynamic compression installed

Next you might look at overriding some compression defaults dynamicCompressionDisableCpuUsage is set to 90% and compression will not kick in again until you go under dynamicCompressionEnableCpuUsage which defaults to 50%. I would suggest raising the latter.

Failed request tracing is also recommended in several places on SO for this kind of problem which might help you spot the issue.

There are some detailed answers to the following questions

How can I get gzip compression in IIS7 working?

Compression is not working

UPDATE:

The setting may be locked at the application level and so you should try running the following:

appcmd set config -section:urlCompression /doDynamicCompression:true

If it's still an issue it might be worth tweaking minFileSizeForComp whose default has increased with later IIS versions.

As per comment, also try just doing dynamic to start and leave off static while you're trying to nail this.

Related Topic