5

I have IIS 7.5 with static and dynamic compression enabled. It seems to work fine for dynamic files, but for static ones it behaves erratically, often sending a http header "Content-Encoding: gzip" when the content is not compressed. This causes browsers to attempt to uncompress, throwing an invalid magic number error. Here's my configuration:

  <httpCompression dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="70" >
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/json" 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="*/*" enabled="false" />
  </staticTypes>

I thought some http module was uncompressing the content somewhere down the pipe, but none of them seem suspicious. Any ideas?

user865984
  • 73
  • 1
  • 5

3 Answers3

2

I have found out in my investigations that using HttpContext.RewritePath() on a static file causes this problem.

sboisse
  • 4,860
  • 3
  • 37
  • 48
  • It is strange but I am seeing this to be true as well, at least on one of my QA servers (W2K8/IIS 7.5). – rsbarro Nov 24 '14 at 19:57
2

Try to enable dynamic compression before cache which is disabled by default.

    <urlCompression dynamicCompressionBeforeCache="true" doDynamicCompression="true" doStaticCompression="true" />
Softlion
  • 12,281
  • 11
  • 58
  • 88
  • 1
    Thanks for suggesting. I tried putting that line under but it did not make a difference. Any idea? – sboisse Oct 25 '12 at 17:19
0

Took me a while to figure this out too. Setting the frequentHitThreshold attribute to 1 on the system.webServer/serverRuntime node in the applicationHost.config file should do the trick, as documented at http://www.iis.net/ConfigReference/system.webServer/serverRuntime.

You can do this by executing the following command as an administrator:

%windir%\system32\inetsrv\appcmd set config /section:serverRuntime /frequentHitThreshold:1 /commit:apphost

A word of warning - the "frequent hit" concept does not seem specific to compression. I have no idea whether there are other consequences as a result of setting this!

Dale Anderson
  • 1,681
  • 16
  • 15