13

是否可以在简单的 Azure 网站上启用 gzip 压缩?如果是这样,怎么办?在 Azure 网站上应用 gzip 时有什么需要考虑的吗?

4

2 回答 2

11

我刚刚检查了我的一个 azure 网站,它看起来确实 gzip 正在工作。我的 web.config 中没有任何特别之处,所以我认为它必须默认启用。

于 2013-02-11T04:45:14.627 回答
3

根据@DavideB 对已接受答案的评论,我发现您可以通过 web.config 为 Azure / IIS 配置它。[ 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>

请注意:

  1. 这仅适用于 Azure 或安装了正确功能的 IIS(即,如果您使用的是 IISExpress 或 vanilla IIS,那么您就不走运了,请参阅文章了解正确的功能和本地测试的配置说明)。

  2. 静态和动态资源的压缩是独立配置的,有各自的默认值;实际上,您应该比我更仔细地配置您的 mimetypes 和压缩级别。

  3. 压缩级别介于 0 和 10 之间,其中 0 == 关闭,10 == 最大值;在这里,我将我的设置为 7,原因是它可能是 CPU 使用率和压缩率之间的良好折衷。

于 2015-12-02T04:35:57.067 回答