7

I want to enable gzip compression for my site running on ASP.NET4.5 with IIS7.5, but can't get it to compress.

I'm on shared hosting, so I can't set this in IIS directly.

applicationHost.config

I changed this from Deny to Allow (I read here that I should not change the allowDefinition setting: How do you change the allowDefinition section attribute using appcmd in IIS 7?)

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Allow" />

my website's web.config

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
  <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/javascript; charset=utf-8" 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/javascript; charset=utf-8" enabled="true"/>
    <add mimeType="*/*" enabled="false"/>
  </staticTypes>
</httpCompression>    

As an alternative to the above I also tried adding this to my web.config:

<configuration>
   <system.webServer>
      <urlCompression doStaticCompression="true" doDynamicCompression="false" />
   </system.webServer>
</configuration>

I see in the Windows 2008 server manager that Static content compression is installed, but Dynamic is not.

Then when I go to IIS to my site and the module compression I see now that Enable Dynamic content compression is enabled (even though apparently not installed) but grayed out, and static content compression is checked.

enter image description here

Nonetheless: even though both static and dynamic content compression are enabled, I see no compression occurring using Fiddler.

The Decode button is not enabled in Fiddler. I also checked with http://www.whatsmyip.org/http-compression-test/ and http://www.gidnetwork.com/tools/gzip-test.php

But whatever I do, when I check with Fiddler I see no gzip compression: enter image description here

I already checked these posts:

http://blog.arvixe.com/how-to-enable-gzip-on-iis7/

Enable IIS7 gzip

Community
  • 1
  • 1
Adam
  • 6,041
  • 36
  • 120
  • 208
  • Did you look through these answers about auto-decode and also possibly checking with a third-party like Port80? http://stackoverflow.com/q/897989/231316 – Chris Haas Jan 19 '14 at 16:07
  • I updated my post. I tested with other sites as well. Which Port80 product should I test with: http://www.port80software.com/download/ ? – Adam Jan 19 '14 at 17:29
  • Here's the link to their online tester: http://www.port80software.com/tools/compresscheck.asp?url=Enter+URL – Chris Haas Jan 19 '14 at 19:10
  • That too indicates no compression: http://www.port80software.com/tools/compresscheck.asp?url=http://www.toptrouwen.nl – Adam Jan 19 '14 at 19:31
  • 4
    I tried accessing one of your jquery files and I got an uncompressed one. Then I read this (http://stackoverflow.com/a/15626988/231316) and it said that IIS won't compress something unless its accessed "often". So I refreshed a bunch of times and finally received a compressed version on the third try. That link includes a way to change your "often" parameter. Your dynamic content still isn't coming over as compressed but you said that wasn't installed. – Chris Haas Jan 20 '14 at 14:18
  • Thanks, this seems helpful. I checked that link and configured my server now as is listed there. How do I validate if a jquery file is compressed? Since in Fiddler I get `No response body` on requests to jQuery files. – Adam Jan 20 '14 at 16:41
  • I just used Chrome's developer tools, switched to the Network tab, requested the file and then shift-refreshed a couple of times. – Chris Haas Jan 20 '14 at 16:43
  • I guess it works now, although I still do need to figure out how to configure it to work consistently :) – Adam Jan 20 '14 at 17:40
  • Have you tried setting `frequentHitThreshold` to `1`? – Chris Haas Jan 20 '14 at 18:01
  • Yes, that is already set to 1...do you see any different behavior now? – Adam Jan 20 '14 at 18:04
  • Yep, everything appears to be compressed on the first hit. – Chris Haas Jan 20 '14 at 18:09

1 Answers1

5

Compression on IIS is a bit wonky in that it doesn't take immediately. IIS doesn't compress content until it is hit frequently, so it may appear that content is not compressed when it actually will be eventually after it's been hit a few times.

Additionally make sure that your mime types listed match the content types you're passing back from your code EXACTLY.

For example for JavaScript:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="application/javascript; charset=utf-8" enabled="true" />
    <add mimeType="application/json" enabled="true" />
    <add mimeType="application/json; charset=utf-8" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/atom+xml" enabled="true" />
    <add mimeType="application/xaml+xml" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </staticTypes>
</httpCompression>

might be required.

Here's more info from a blog post I wrote a few years back: http://weblog.west-wind.com/posts/2011/May/05/Builtin-GZipDeflate-Compression-on-IIS-7x

And another that talks about some issues that sound similar to yours (look in the comments): http://weblog.west-wind.com/posts/2007/Jun/22/IIS-7-and-JavaScript-Compression-not-working-consistently

Rick Strahl
  • 17,302
  • 14
  • 89
  • 134