Setting the gzip compression in asp.net

2019-01-13 11:00发布

问题:

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?

回答1:

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>


回答2:

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)



回答3:

It can be complicated or even impossible to modify the applicationHost.config on all environments.

So why not simply gzip in code as shown in this post http://laubplusco.net/gzip-svg-files-asp-net/