GZip Compression On IIS 7.5 is not working

Solution 1:

After a lot of searching, I finally found what got compression working on my IIS 7.5. To start with, IIS will not compress a file unless it loaded often enough. That brings up the question "what does IIS consider often enough?" Well, the defaults are 2 times every 10 seconds. Yikes!

This setting can be changed in web.config, but the section needs to be unlocked first in applicationHost.config. Here are the commands:

First unlock the section:

C:\Windows\System32\inetsrv\appcmd.exe unlock config /section:system.webServer/serverRuntime

Unlocked section "system.webServer/serverRuntime" at configuration path "MACHINE/WEBROOT/APPHOST".

Now that is done, edit the web.config file and add the serverRuntime element:

<?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <system.webServer>
      <serverRuntime frequentHitThreshold="1" frequentHitTimePeriod="10:00:00" />
...

In this case, I set it to hit the file once in a 10 hour period. You can adjust the values as necessary. Here is the document that explains the serverRuntime element:

http://www.iis.net/configreference/system.webserver/serverruntime

I hope this helps get your compression working as well.

Note: you can also set the serverRuntime element up in the applicationHost.config file, but I chose to change it in the web.config because we have a number of servers and farms with various sites, and it is easier for me to control it from this level of granularity.

Solution 2:

One thing to keep in mind is that the first hit usually is returned uncompressed immediately, but spins up a thread to compress the file in the background in order to service the response with compression for future requests.

Also, have you tried using a different client (e.g. IE)?

Solution 3:

Make sure you install Dynamic Compression on the server. Add/Remove Features under IIS.

Solution 4:

Took me a while to figure this out too. Setting the frequentHitThreshold attribute to 1 on the system.webServer/serverRuntime node in the applicationHost.config file should do the trick, as documented at http://www.iis.net/ConfigReference/system.webServer/serverRuntime.

You can do this by executing the following command as an administrator:

%windir%\system32\inetsrv\appcmd set config /section:serverRuntime /frequentHitThreshold:1 /commit:apphost

A word of warning - the "frequent hit" concept does not seem specific to compression. I have no idea whether there are other consequences as a result of setting this!