IIS7 Compression CSS files only compressed when dynamic compression is enabled

compressioniis-7

If anyone can help it would be appreciated. I would like to enable compression for static files within IIS7 (for the sake of simplicity I'll just refer to static css files for the time being).

The problem I'm getting is that css files are only compressed when both dynamic and static compression is enabled in IIS for the website. What I really want to achieve is css compression (static file) whilst leaving the dynamic (aspx) pages as uncompressed for the time being (to avoid unnecessary CPU load).

I am puzzled as to why just leaving 'static compression' enabled causes css files to be returned uncompressed.

My applicationHost.config file has not be altered and looks like this:

        <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </staticTypes>
        <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
    </httpCompression>

The server-wide compression setting within IIS is set to 'Dynamic Disabled' and 'Static Enabled' from the Server > Features > Compression page.

The web-site compression setting (Server > Sites > MyWebsite > Features > Compression) is where I am enabling and disabling dynamic compression as detailed above.

Any help would be really help me get unstuck on this.

Thanks

Best Answer

Chances are, your CSS file is being served by a dynamic content handler, which means it's considered dynamic content by IIS. If .CSS files are mapped directly to the StaticFileHandler, they'll probably be compressed along with other static content, as long as the mime-type is correct.

To work out whether that's the case:

Turn on Failed Request Tracing for the site, and enable a rule that traces on 200 responses.

Open the failed request log file corresponding with a .CSS request, and check to see which handlers are being invoked to produce the file, and whether compression was regarded as being required. Wildcard script mappings are often the cause of this type of behaviour.

If you don't score more than frequentHitThreshold requests in frequentHitTimePeriod (typically 2 in 10 seconds, if memory serves), the content may not be compressed until breaking that threshold - the same threshold is used for compression as caching.

Related Topic