IIS only GZIPs some assets and only sometimes

I had an issue on a server running IIS 8 not consistently compressing my .js, .css and other files. It turned out the issue had something to do with the CPU load.

To this issue the solution was to open the applicationHost.config file (C:WindowsSystem32inetsrvconfig – remember to backup this file!). Remeber to open this in a 64 bit text editor like notepad.

In the  <httpCompression directory=”%SystemDrive%inetpubtempIIS Temporary Compressed Files”>  section I added staticCompressionDisableCpuUsage=”100″ staticCompressionEnableCpuUsage=”100″

This tells the server to not disable the compression of static assets. Furthermore, I added  maxDiskSpaceUsage=”500″ noCompressionForHttp10=”false” noCompressionForProxies=”false” . The two last parts for CDN.

The final section looks like this

<httpCompression directory="%SystemDrive%inetpubtempIIS Temporary Compressed Files" maxDiskSpaceUsage="500" noCompressionForHttp10="false" noCompressionForProxies="false" staticCompressionDisableCpuUsage="100" staticCompressionEnableCpuUsage="99">
    <scheme name="gzip" dll="%Windir%system32inetsrvgzip.dll" staticCompressionLevel="9" />
        <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="*/*" enabled="false" />
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="*/*" enabled="false" />

I also changed the <serverRuntime />  to <serverRuntime frequentHitThreshold=”1″ enabled=”true” />  so the server compresses the the file event though it is not loaded that often as it is behind a CDN.

Restart the server (in IIS manager) and you should be all set.

You should be able to change this in the web.config if the overrride is allowed in the applicationHost.config file.

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />


<section name="serverRuntime" overrideModeDefault="Allow" />

However, I couldn’t get that working and the other solution did work for me.






Leave a Reply

Your email address will not be published. Required fields are marked *