Fixing the problem with Static Compression Module frequentHitThreshold

While trying to speed up my website, I struggled with getting the StaticCompressionModule to work on my local machine. By default, the static compression module is enabled so you would think that all your static files like javascript and css will be gzipped before being sent to your browser. However this is not necessarily the case as I found out with Chrome Developer Tools and the Firefox YSlow plugin.

Although the module is enabled, static files are only going to be compressed if they meet a certain criteria determined by the frequency of access controlled by two parameters (frequentHitThreshold and frequentHitTimePeriod). The first parameter is set to 2 and the second one to 10 seconds by default. This means that if a period of 10s, if you get 2 request for your static files then they will be sent as gzip. However this is not what I wanted and I needed to correct this behaviour.

It is possible to change the values for these parameters but when I put it in the web.config file, I got the following error:

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”.

I googled the problem and thought I’d give the command line a try:

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/serverRuntime -frequentHitThreshold:1

Substitute your windir accordingly.

That worked great but I wanted to know why the web.config gave an error and it turned out that the config needed to be within a location tag  as follows:

<location path="Default Website">
 <serverRuntime enabled="true" frequentHitThreshold="1" frequentHitTimePeriod="00:00:10" />

Once the value of the frequentHitThreshold was changed to 1, I was able to see the content compressed before being sent out from the server to the browser. Sweet!

comments powered by Disqus