Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GZip compression in IIS7 not working, but content-encoding header is set to gzip

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?

like image 681
user865984 Avatar asked Oct 10 '22 08:10

user865984


2 Answers

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

    <urlCompression dynamicCompressionBeforeCache="true" doDynamicCompression="true" doStaticCompression="true" />
like image 116
Softlion Avatar answered Oct 14 '22 02:10

Softlion


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

like image 43
sboisse Avatar answered Oct 14 '22 01:10

sboisse