简体   繁体   English

Windows Azure网站中的gzip压缩

[英]gzip compression in Windows Azure Websites

Is it possible to Enable gzip compression on a simple Azure Website? 是否可以在简单的Azure网站上启用gzip压缩? If so how can it be done? 如果是这样,怎么办呢? Is there anything to take under consideration when applying gzip on Azure Websites? 在Azure网站上应用gzip时有什么需要考虑的吗?

I just checked one of my azure web sites and it does look like gzip is working. 我刚刚查看了我的一个天蓝色网站,它确实看起来像gzip正在工作。 I don't have anything special in my web.config so I think it must be enabled by default. 我的web.config中没有任何特殊内容,所以我认为默认情况下必须启用它。

Per @DavideB's comment on the accepted answer, I found out that you can configure this for Azure / IIS via web.config. 根据@ DavideB对已接受答案的评论,我发现您可以通过web.config为Azure / IIS配置此项。 [ MSDN source ] [ MSDN来源 ]

<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). 这只适用于Azure,或者安装了正确功能的IIS(例如,如果您使用的是IISExpress,或者说您运气不好,请参阅文章了解正确的功能以及本地测试的配置说明)。

  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. 在实践中,你应该比我更仔细地配置你的mimetypes和压缩级别。

  3. Compression Level is between 0 and 10, where 0 == off, and 10 == maximum; 压缩级别介于0和10之间,其中0 ==关闭,10 ==最大; Here, I've set mine to 7, with the reasoning that it's probably a good trade off between CPU usage and compression. 在这里,我将我的设置为7,理由是它可能是CPU使用和压缩之间的良好折衷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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