IIS 7.5 ASP.NET-4 Gzip compression

2020-06-12 02:59发布

I just can't seem to get GZIP compression enabled for my ASP.NET 4 application. Only javascript files seem to get compressed. The page, css and others dont get compressed.

The response header of a not compressed CSS file is:

Content-Type      text/css
Last-Modified     Mon, 09 Aug 2010 20:10:34 GMT
Accept-Ranges     bytes
Etag               "5d71bdecfe37cb1:0"
Server    Microsoft-IIS/7.5
Date               Sat, 28 Aug 2010 14:33:56 GMT
Content-Length    3364

And for a Javascript file that gets compressed (scriptresource.axd):

Cache-Control      public
Content-Type       application/x-javascript
Content-Encoding gzip
Expires    Sun, 28 Aug 2011 14:33:50 GMT
Last-Modified      Sat, 28 Aug 2010 14:33:50 GMT
Server     Microsoft-IIS/7.5
Date                Sat, 28 Aug 2010 14:33:56 GMT
Content-Length     478

In applicationHost.config:

    <httpCompression sendCacheHeaders="false" directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" noCompressionForRange="true">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
        </staticTypes>
        <dynamicTypes>
        </dynamicTypes>
    </httpCompression>

And in the app web.config:

<urlCompression  doStaticCompression="true" doDynamicCompression="true" dynamicCompressionBeforeCache="true" />
<httpCompression noCompressionForRange="false" noCompressionForHttp10="false" noCompressionForProxies="false" >
  <dynamicTypes>
    <add mimeType="text/css" enabled="true" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/css" enabled="true" />
  </staticTypes>
</httpCompression>

Can anybody tell me what setting I am missing?

1条回答
\"骚年 ilove
2楼-- · 2020-06-12 03:47

I found out what the problem was... In Turn Windows features on or off -> WWW -> Performance features, the static & dynamic compression was not enabled (pretty stupid).

The reason the Javascript was compressed is probably because ScriptResource.axd implements a custom gzip encoding.

查看更多
登录 后发表回答