Why is gzip compression not working on IIS 8.5?

mrcoulson picture mrcoulson · Jul 21, 2017 · Viewed 7.2k times · Source

I am unable to get gzip compression working on IIS 8.5 on a Server 2012 R2 machine. I have done some research and followed the instructions found in these posts:

  1. How to enable GZIP compression in IIS 7.5
  2. Compression in IIS 8.5 not successful, stating ALREADY_CONTENT_ENCODING
  3. GZip Compression On IIS 7.5 is not working
  4. gzip compression not working with IIS 8.5

Here is the relevant section of my config:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" staticCompressionIgnoreHitFrequency="true">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <!-- I have read that dynamic compression increases server CPU load.
    <dynamicTypes>
        <add mimeType="text/*" enabled="true"/>
        <add mimeType="message/*" enabled="true"/>
        <add mimeType="application/javascript" enabled="true"/>
        <add mimeType="*/*" enabled="false"/>
    </dynamicTypes>
    -->
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />

Also, in IIS, I set compression to apply to anything larger than 256 bytes. And I have performed iisreset.

Nonetheless, I don't see the compression mentioned in my dev console in Chrome or IE and PageSpeed still tells me to compress stuff. What simple step have I missed?

Answer

Rohith picture Rohith · Jul 22, 2017

It will be difficult to understand what is happening.Assuming that you have done all the IIS settings correct.

  • For checking if compression is working fine or not,How are you accessing the website. e.g. If you use an FQDN www.example.com ,please try and use localhost url. This will make sure your IIS settings are correct.
  • If localhost works fine and your Fully Qualified domain name does not work,then problem can be in the network.In order for compression to work,the browser needs to send request header accept-encoding:gzip, deflate . many at times your proxy or load balancer can trim this header and this header may not reach the IIS server.So IIS will never compresseven if all the settings are done right.

To verify what is happening for the request and why IIS did not compress the request,you can do the following.

  • make sure you have Failed Request tracing installed.
  • Configure your Failed Request Definition
    • Go to Failed Request tracing Modules
    • Click Add on the sidebar Failed Request tracing
    • Enable All Content and status as 200-999
    • And Finish the configuration.
    • Now reproduce the issue and you will get a traces captured in directory C:\inetpub\logs\FailedReqLogFiles\W3SVC .
    • Open the trace file(for each requests one file will be generated.Open the trace file in IE(make sure the request details matches the request you would like to verify) and go to the compact view Failed Request tracing Compact View
    • Search for Compression and also check the reason Dynamic Compression failed Reason