8

I'm trying to enable dynamic compression for the mime type application/json.

In applicationHost.config, I've made the following change:

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Allow" />

I also tried unlocking the section with the following command:

appcmd unlock config /section:system.webserver/httpcompression

My web.config settings (same as applicationHost.config but with additional mimetype):

    <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/x-javascript" enabled="true" />
            <add mimeType="application/atom+xml" enabled="true" />
            <add mimeType="application/xaml+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/json" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
    </httpCompression>

But the response is not being gzipped. I know the settings are correct as it works if I add the mimetype directly to applicationHost.config.

I've enabled Failed Request Tracing and no errors are produced.

Ben
  • 243
  • 3
  • 9

3 Answers3

3

Try also adding the mime type:

 <add mimeType="application/json; charset=utf-8" enabled="true" />
JeremyBeadle
  • 131
  • 2
1

I'm having the same problem i.e. trying to get IIS (IIS 10 in my case) to gzip application/json but have discovered a workaround.

I've tried editing the ApplicationHost.config as well as the web.config with no luck. IIS simply ignores any compress settings for .json data. It will happily gzip any other mimetype you tell it compress though. So I changed the mimetype to text/json in web.config and now I have gzipped reponses:

<system.webServer>
  <staticContent>
    <remove fileExtension=".json" />
    <mimeMap fileExtension=".json" mimeType="text/json" />
  </staticContent>
  <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
    <dynamicTypes>
      <add mimeType="text/json" enabled="true"/>
    </dynamicTypes>
    <staticTypes>
      <add mimeType="text/json" enabled="true"/>
    </staticTypes>
  </httpCompression>
  <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>

Of course that may break other stuff - because now your response has Content-Type:text/json

Ilan
  • 111
  • 2
0

HttpCompression from web.config is possible only if you use IIS 10. On IIS 7.5 you'll have to use it on appHost.config.

I was also fighting it until I've found that info on this post.

BornToCode
  • 252
  • 2
  • 7