Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gzip compression not working even though allowed in applicationHost.config

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

like image 323
Adam Avatar asked Jan 16 '14 08:01

Adam


People also ask

How do I enable gzip compression?

It's also one of the two recommended web servers by WordPress. To enable GZIP compression on Apache servers, you need to use its mod_filter and mod_deflate modules and configure them properly with the right directives. They will direct Apache to compress server output before sending it to clients over the network.

How do you check gzip compression is enabled or not?

Double click on the file and select headers. Under 'Response headers' you are looking for the 'Connection-Encoding' field, it will say gzip if it is enabled.

How do I enable gzip in Apache?

To turn on Gzip compression, simply add on to the gzip directive in the main Nginx configuration file. $ sudo nano /etc/nginx/nginx. conf gzip on; Add file types to compress.


1 Answers

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

like image 86
Rick Strahl Avatar answered Sep 23 '22 02:09

Rick Strahl