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.

5
  • can u also try to add this under system.webServer node: <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    – tugberk
    Sep 11, 2012 at 10:11
  • Unfortunately this made no difference. Also, in IIS 7.5 the default value for doDynamicCompression changed to true.
    – Ben
    Sep 11, 2012 at 10:19
  • do your changes work in IIS Express?
    – tugberk
    Sep 11, 2012 at 10:20
  • no, had to do the same thing (change applicationHost.config directly)
    – Ben
    Sep 11, 2012 at 11:41
  • Did you ever resolve this issue?
    – Mario
    Sep 19, 2012 at 17:58

3 Answers 3

3

Try also adding the mime type:

 <add mimeType="application/json; charset=utf-8" enabled="true" />
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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .