23

Is there a way to set the gzip compression at the web.config level or can I only do this in the IIS management console?

Micah
  • 111,873
  • 86
  • 233
  • 325
  • possible duplicate of [How to implement GZip compression in ASP.NET?](http://stackoverflow.com/questions/552317/how-to-implement-gzip-compression-in-asp-net) – Chris Moschini Apr 18 '14 at 21:58

2 Answers2

37

Here try this: Sped my site up by about 400% percent. Worked on first try.

Activate GZip with web.config

<system.webServer>
  <httpCompression directory="%SystemDrive%\inetpub\
temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
    <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"/>
</system.webServer>
brenjt
  • 15,997
  • 13
  • 77
  • 118
  • 2
    Tried several times but if these settings are set in web.config, compression does not work. If settings are set in applicationhost.config, everything works. I do not like to set settings in applicationhost.config, but at least it is working. – Karel Kral Nov 19 '12 at 15:51
  • My shared hosting provider manages my permissions using Plesk and got this solution to fail for me too. I've explained in short the lengthier solution I put-together at http://stackoverflow.com/a/14509007/1624169 – Chawathe Vipul S Jan 24 '13 at 19:22
  • Microsoft agrees. http://www.iis.net/configreference/system.webserver/httpcompression But this appears to already be setup by default when you install gzip compression so this step should be unnecessary, and it only minifies content like js, not the HTML of ASP.Net pages. – Chris Moschini Jun 27 '14 at 16:54
  • HTML not gzipping even after the above turns out to be the fault of this obscure setting: http://stackoverflow.com/a/15626981/176877 – Chris Moschini Jun 27 '14 at 19:58
  • If Javascript isn't compressed, try the MIME type "application/x-javascript" instead. – Christian Davén Aug 28 '14 at 07:15
  • Could you tell me where the web.config is located, I found multiple on my server. – Tassisto Jan 30 '17 at 17:11
  • @ChristianDavén can I put between staticTypes and/or dynamicTypes tags? – Tassisto Jan 30 '17 at 17:17
7

Yes you can enable compression with the web.config, as the article below shows- but it can depend on the permissions on the server allows sites.

You should note that dynamic compression (anything that needs to be processed before ti can be sent to the client) can increase the load on the server because its having to do compression on every single request.

IIS7 Compression


Edit: note this is for IIS7 (as you have tagged)

meandmycode
  • 17,067
  • 9
  • 48
  • 42
  • This change will gzip js and css, but not the actual HTML output from ASP.Net, for some reason. You'd thing setting dynamic content compression to enabled would do the trick, but in my testing it does not. – Chris Moschini Jun 27 '14 at 17:00