简体   繁体   中英

gzip compression in Windows Azure Websites

Is it possible to Enable gzip compression on a simple Azure Website? If so how can it be done? Is there anything to take under consideration when applying gzip on Azure Websites?

I just checked one of my azure web sites and it does look like gzip is working. I don't have anything special in my web.config so I think it must be enabled by default.

Per @DavideB's comment on the accepted answer, I found out that you can configure this for Azure / IIS via web.config. [ MSDN source ]

<configuration>
  <system.webServer>

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
      <scheme name="gzip" dll="%windir%\system32\inetsrv\gzip.dll" 
              doDynamicCompression="true" doStaticCompression="true"
              staticCompressionLevel="7" dynamicCompressionLevel="7" />

      <staticTypes>
        <add mimeType="*/*" enabled="true" />
      </staticTypes>
      <dynamicTypes>
        <add mimeType="*/*" enabled="true" />
      </dynamicTypes>

    </httpCompression>

  </system.webServer>
</configuration>

Please note:

  1. This will only work in Azure, or with IIS with the correct features installed (ie if you're using IISExpress, or vanilla IIS you're out of luck, see the article for the correct features, and configuration instructions for local testing).

  2. The compression of Static and Dynamic resources are configured independently, and have separate default values; in practice you should configure your mimetypes and compression levels more carefully than I have.

  3. Compression Level is between 0 and 10, where 0 == off, and 10 == maximum; Here, I've set mine to 7, with the reasoning that it's probably a good trade off between CPU usage and compression.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM