How to compress all files with IIS

折月煮酒 提交于 2020-08-09 13:56:26

问题


IIS compression has been enabled:

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:

Unfortunately, other files are not compressed:

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

Could anyone provide a tip on how to diagnose this?


回答1:


  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 megabaytes.

    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>


来源:https://stackoverflow.com/questions/63088626/how-to-compress-all-files-with-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!