Azure Web App 不使用 GZip 压缩 [英] Azure Web App Not Using GZip Compression

查看:24
本文介绍了Azure Web App 不使用 GZip 压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WebPageTest 来测试我的 Azure Web 应用程序 (ASP.Net vNext Web API/Angular) 的性能.我的压缩传输"和缓存静态内容"都得到了 F.

I was using WebPageTest to test the performance of my Azure Web App (ASP.Net vNext Web API/Angular). I got an F for both "Compress Transfer" and "Cache Static Content".

在搜索 StackOverflow 和 Google 之后,我在 web.config 中添加了以下内容:

After searching StackOverflow and Google, I added the following to my web.config:

<urlCompression doStaticCompression="true" doDynamicCompression="true" />
    <httpCompression>
      <dynamicTypes>
        <clear />
        <remove mimeType="*/*" />
        <add enabled="true" mimeType="text/*"/>
        <add enabled="true" mimeType="message/*"/>
        <add enabled="true" mimeType="application/x-javascript"/>
        <add enabled="true" mimeType="application/javascript"/>
        <add enabled="true" mimeType="application/json"/>
        <add enabled="false" mimeType="*/*"/>
        <add enabled="true" mimeType="application/atom+xml"/>
        <add enabled="true" mimeType="application/atom+xml;charset=utf-8"/>
      </dynamicTypes>
      <staticTypes>
        <clear />
        <remove mimeType="*/*" />
        <add enabled="true" mimeType="text/*"/>
        <add enabled="true" mimeType="message/*"/>
        <add enabled="true" mimeType="application/javascript"/>
        <add enabled="true" mimeType="application/atom+xml"/>
        <add enabled="true" mimeType="application/xaml+xml"/>
        <add enabled="true" mimeType="application/json"/>
        <add enabled="false" mimeType="*/*"/>
      </staticTypes>
    </httpCompression>

<staticContent>
      <!-- Set expire headers to 30 days for static content-->
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>

重新部署我的 Web 应用程序后,我重新运行了测试,但我仍然得到了两个 F.尽管我已将这些设置添加到 web.config,但 Azure Web App 似乎并未支持它们.

After redeploying my Web App, I re-ran the test and I am still getting an F for both of them. Even though I have added these settings to web.config, it does not appear that Azure Web App is honoring them.

另外,我发现一些 Web 应用程序层不允许压缩,但我在 S2 上运行,我验证它确实允许压缩.

Also, I found out that some Web App tiers do not allow compression but I am running on an S2 and I verified that it does allow compression.

任何帮助将不胜感激!

谢谢!

推荐答案

默认情况下为 Azure Web 应用启用 gzip 压缩.您可以在站点 LocalSiteRoot/Config/applicationhost.config 中查看规则.查看响应标头(可以使用开发人员工具轻松完成)应该确认正在使用 gzip.您的站点加载的资源之一可能未压缩,这会导致 WebPageTest 失败.如果您担心,我会查看网络捕获和响应标头,看看是否可以找到违规资源.

gzip compression is enabled by default for Azure Web Apps. You can see the rules in your sites LocalSiteRoot/Config/applicationhost.config. Looking at the response headers (which can easily be done with developer tools) should confirm that gzip is being used. It is possible that one of the resources that your site loads is not compressed, and this is causing the WebPageTest to fail. I would look at a network capture and the response headers, and see if you can find the offending resources if you're concerned.

要转至本地站点根目录,您可以使用 FTP,或通过 https://.scm.azurewebsites.net/DebugConsole 转至您的 SCM 站点,然后单击地球图标.

To go to the local site root, you can use FTP, or go to your SCM site at https://.scm.azurewebsites.net/DebugConsole and then click the globe icon.

我还怀疑您的 2 个 javascript 文件没有被压缩,因为 Content-Type 标头没有被填充,所以规则没有捕获它,因为它无法识别 mimetype.

Also I suspect that your 2 javascript files are not getting compressed since the Content-Type header is not getting populated, so the rule is not capturing it because it does not recognize the mimetype.

这篇关于Azure Web App 不使用 GZip 压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆