8

I have the following web.config:

<urlCompression doStaticCompression="true" />
        <httpCompression>
            <dynamicTypes>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/javascript" 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="*/*" enabled="false" />
            </staticTypes>
        </httpCompression>

May plan does not allow Dynamic compression

The problem is, when I request css or js, IIS respond with GZIP and add vary:accept-encoding sometime and other time does not compress CSS nor JS, I can't find the pattern it is some kind of random.

I always try CTRL F5, even when you access www.mysite.com css and js are randomly compressed or not.

NB: hosted on NetworkSolution.

What's wrong with my config or IIS.

Thanks

Sameh
  • 934
  • 1
  • 14
  • 40
  • When I try http://cdn.novopath.com/content/css/master.css on http://www.whatsmyip.org/http-compression-test/ the first time says not compressed the second time says compressed! – Sameh Mar 19 '13 at 13:00

1 Answers1

17

After a lot of searching, I finally found what got compression working more consistently 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

<?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 properly.

Brain2000
  • 4,655
  • 2
  • 27
  • 35
  • I made a recent answer here which will provide a little more explanation: http://stackoverflow.com/questions/14796225/gzip-js-in-iis-doesnt-get-compressed-if-static-compression-enabled/24906331#24906331 – ianbeks Jul 23 '14 at 09:12
  • this apply even to dynamic content compression ? – TheQult Sep 06 '17 at 15:52