26

I want to compress responses coming from my IIS Express driven web application. We're using IIS Express as local development webserver and IIS on staging and on our build machines. I have found many guides on enabling gzipped responses on IIS but none for IIS Express. Is it even possible?

Phil
  • 3,934
  • 12
  • 38
  • 62

2 Answers2

38

You can enable compression in IIS Express, just like for IIS.

  1. Start command prompt and go to IIS Express installation folder (%PROGRAMFILES%\IIS Express)

  2. Run following command

appcmd set config -section:urlCompression /doDynamicCompression:true

To add compression for JSON run the following two commands from the IIS Express installation directory:

appcmd set config /section:staticContent /+[fileExtension='.json',mimeType='application/json']

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost

Make sure to restart IIS Express.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
vikomall
  • 17,379
  • 6
  • 49
  • 39
  • I get gzip-compression on javascript files and html files. But the json still doesn't get compressed. I've added the mimetype "application/json" to both the web config and app config. Any ideas? – Phil Apr 16 '12 at 06:58
  • Run following two commands from the IIS Express installation directory and see if that works (make sure that you restart IIS Express after running these commands). (1) appcmd set config /section:staticContent /+[fileExtension='.json',mimeType='application/json'] (2) appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost – vikomall Apr 16 '12 at 17:14
  • You can omit the first command--the one that modifies staticContent--if you don't serve .json files statically. If you're like me, you only serve JSON in HTTP POST responses. – NathanAldenSr Mar 11 '13 at 18:05
  • The same commands work for IIS 8 as well, and I assume for 7/7.5. – Martin-Brennan Nov 05 '13 at 03:52
  • 7
    You can also edit the .config file directly in ``{MyDocumentsFolder}\IISExpress\applicationhost.config`` – Siewers May 21 '15 at 10:18
  • to go to IIS Express folder using CMD, you can also try : `pushd C:\Program Files\IIS Express` – Shaiju T Feb 28 '16 at 15:39
3

For Visual Studio 2019 I found the above does not work, as the applicationhost.config file is unique to the project. This file is stored in .vs\<solution_name>\config\applicationhost.config. For VS 2017 it isnt in the solution subfolder.

Thus the solution for me was to replace <httpCompression/> with the following.

<httpCompression directory="%TEMP%\iisexpress\IIS Temporary Compressed Files">
            <scheme name="gzip" dll="%IIS_BIN%\gzip.dll" />
            <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="application/json" 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="application/atom+xml" enabled="true" />
                <add mimeType="application/xaml+xml" enabled="true" />
                <add mimeType="image/svg+xml" enabled="true" />
                <add mimeType="*/*" enabled="false" />
            </staticTypes>
        </httpCompression>
Aveer28
  • 127
  • 11