1
votes

My IIS 7 dynamic content compression will not work as verified by server logs... bytes sent/received are identical with compression on and off.

Let me go through the things I've done so far to make sure this is done right:

1) Install dynamic compression module (duh)
2) Enable dynamic compression
3) in web.config under system.webserver/httpCompression, I've added DynamicCompressionDisableCpuUsage=100 and DynamicCompressionEnableCpuUsage=99 to make sure that compression is on as often as possible. server load is generally 0% to 2% CPU, so this shouldn't be a problem at all.
4) I changed system.webserver/httpCompression/scheme dynamicCompressionLevel from 0 to 7 since the default value is 0
5) I've added the mime types and set enabled=true under system.webserver/httpCompression/dynamicTypes and ensured via a request analyzer that mimetype is indeed correct
6) After this, I've even restarted sites/recycled app pool.
7) I've even added mime-types to include the the charset, which I've read places sometimes affects dynamic compression.

I've still got no reduction in traffic! What gives!? I even set system.webserver/httpCompression/minFileSizeForComp to 1000B even though that's only for static compression thinking that perhaps it might somehow carry over to dynamic compression. Bytes sent in the logs are still the same as without compression on.

Here's my web.config section FYI:

<system.webServer>
    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" dynamicCompressionDisableCpuUsage="100" dynamicCompressionEnableCpuUsage="99" minFileSizeForComp="1000">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="7" staticCompressionLevel="7"/>
        <dynamicTypes>
            <add mimeType="text/*" enabled="true"/>
            <add mimeType="message/*" enabled="true"/>
            <add mimeType="application/javascript" enabled="true"/>
            <add mimeType="application/x-javascript" enabled="true"/>
            <add mimeType="application/xml" enabled="true"/>
            <add mimeType="application/json" enabled="true"/>
            <add mimeType="application/json; charset=utf-8" enabled="true"/>
            <add mimeType="application/json; charset=UTF-8" enabled="true"/>
            <add mimeType="*/*" enabled="false"/>
        </dynamicTypes>
    </httpCompression>
    <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>

Here are a couple other questions I've referenced to come up with these settings... it seems like I've tried every trick in the book.

How can I get gzip compression in IIS7 working?
https://serverfault.com/questions/200041/how-do-determine-the-dynamiccompressiondisablecpuusage-setting-on-iis7

1

1 Answers

2
votes

as per this ServerFault answer: https://serverfault.com/a/125156/117212 - you can't change httpCompression in web.config, it needs to be done in applicationHost.config file. Here is the code I use in my Azure web role to modify applicationHost.config file and add mime types for compression:

using (var serverManager = new ServerManager())
{
    var config = serverManager.GetApplicationHostConfiguration();
    var httpCompressionSection = config.GetSection("system.webServer/httpCompression");
    var dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes");

    Action<string> fnCheckAndAddIfMissing = mimeType =>
    {
        if (dynamicTypesCollection.Any(x =>
        {
            var v = x.GetAttributeValue("mimeType");
            if (v != null && v.ToString() == mimeType)
            {
                return true;
            }

            return false;
        }) == false)
        {
            ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add");
            addElement["mimeType"] = mimeType;
            addElement["enabled"] = true;
            dynamicTypesCollection.AddAt(0, addElement);
        }
    };

    fnCheckAndAddIfMissing("application/json");
    fnCheckAndAddIfMissing("application/json; charset=utf-8");

    serverManager.CommitChanges();
}

ServerManager comes from Microsoft.Web.Administration package in NuGet.