Search code examples
iiscompressiongziphttp-compression

How to enable compression using IIS


I have followed this document and have enabled both Dynamic and Static compression for my website.

enter image description here

But when I test the website here, the compression is not enabled.

enter image description here

I have verified the HttpCompression:

<system.webServer>
  <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <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="image/svg+xml" 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="application/javascript" enabled="true" />
      <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
  </httpCompression>
</system.webServer>

I have also checked the following IIS Settings: enter image description here


Solution

  • I see from your posted headers that the site is behind cloudfront (ie the via and x-cache headers).

    Thus you may need to investigate having cloudfront provide compressed data: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html

    I'm not particularly familiar with cloudfront, but since its adding the via header its acting as a proxy..

    ..you have noCompressionForProxies = True in your IIS settings screenshot.

    This has some info on changing that setting https://community.spiceworks.com/topic/1989103-help-with-enabling-nocompressionforproxies-in-applicationhost-config-in-iis

    As a 1st test you could try to hit your site by-passing cloudfront to directly test the IIS setup.