Search code examples
iisweb-confighttp-compression

How to compress all files with IIS


IIS compression has been enabled: enter image description here

The following is the httpCompression tag of web.config:

<httpCompression
      directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
      minFileSizeForComp="1"
      staticCompressionIgnoreHitFrequency="true"
      dynamicCompressionIgnoreHitFrequency="true">
  <dynamicTypes>
    <add mimeType="*/*" enabled="true" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="*/*" enabled="true" />
  </staticTypes>
</httpCompression>  

I see only CSS and JavaScript files are compressed when running the web app: enter image description here enter image description here

Unfortunately, other files are not compressed:

enter image description here

I do not seee "IIS Temporary Compressed Files" in "C:\inetpub\temp".

Could anyone provide a tip on how to diagnose this?

Update[2020-08-13] Configuration Editor on Windows Server 2016:

enter image description here

Update[2020-08-13] Per @Kul-Tigin, Dynamic Content Compression needs to be installed: enter image description here


Solution

    1. There's no such a setting named dynamicCompressionIgnoreHitFrequency, remove it.

    2. 1 (in bytes) for minFileSizeForComp is a little bit harsh. Compressing small files just decreases the response size. Leave it 2700 as default.

    3. Unlike setting values on attributes (like you did in staticCompressionIgnoreHitFrequency="true"), adding a setting as node won't override inherited ones.

      Before adding, removing possibly inherited corresponding setting or clear all the inherited ones is a good practice to prevent errors (especially silent ones).

      Otherwise an error may occur or worse a silent error may break your setting.

    4. 100 (in MB) for per application pools space limit may be insufficient for your needs. If I recall correctly most of your files are WebAssembly files of megabytes.

      Since you want all files to be compressed if possible; specify a value big enough.

      Big as if possible; the sum of the uncompressed lengths of all your files. Say 2048 MB.

      With this way you can't reach the disk space limit so none of your compressed caches are not deleted due to lack of space.

      As long as the original file has not changed, the compressed caches survive and be delivered.

      I have 3 years old compressed cache files stored on my servers, ready to be delivered BTW.

    So, give the following a try.

    If it does not work, please provide more information about request headers and the files that are delivered as uncompressed.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <httpCompression 
            sendCacheHeaders="false" 
            directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" 
            doDiskSpaceLimiting="true" 
            maxDiskSpaceUsage="2048" 
            minFileSizeForComp="2700" 
            noCompressionForHttp10="true" 
            noCompressionForProxies="true" 
            noCompressionForRange="true" 
            staticCompressionIgnoreHitFrequency="true" 
            staticCompressionDisableCpuUsage="100" 
            staticCompressionEnableCpuUsage="50" 
            dynamicCompressionDisableCpuUsage="90" 
            dynamicCompressionEnableCpuUsage="50" 
            dynamicCompressionBufferLimit="65536">
              <dynamicTypes>
                <clear />
                <add mimeType="*/*" enabled="true" />
              </dynamicTypes>
              <staticTypes>
                <clear />
                <add mimeType="*/*" enabled="true" />
              </staticTypes>
            </httpCompression>  
        </system.webServer>
    </configuration>