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

11

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.