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" />
    <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="*/*" enabled="false" />
    </dynamicTypes>
    <staticTypes>
        <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" />
    </staticTypes>
</httpCompression>

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" />

and

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

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

Sources:

http://www.codeproject.com/Articles/242133/Making-the-most-out-of-IIS-compression-Part-conf

http://codepolice.net/2012/06/26/problems-with-gzip-when-using-iis-7-5-as-an-origin-server-for-a-cdn/

http://stackoverflow.com/questions/6938713/gzip-compression-on-iis-7-5-is-not-working

http://serverfault.com/questions/505788/why-is-gzip-compression-varying-in-efficiency-in-iis?lq=1

Leave a Reply

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