在Azure App Service上启用gzip压缩

ede*_*esr 9 gzip web-config azure azure-web-sites

我有一个在microsoft azure中托管的Web应用程序.由于本地IIS对静态和动态内容都使用压缩,我希望这也适用于azure平台.因为似乎压缩不起作用,因为例如json和css文件是未压缩的返回:

请求标头

响应头

我试图设置压缩,如在几个帖子中提到的(例如Windows Azure网站中的gzip压缩或者),如果没有对结果进行任何更改:

<system.webServer>
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
  <httpCompression>
    <dynamicTypes>
    <clear />
    <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 />
    <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>
[...]
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

因为看起来天蓝色的门户网站没有给我任何改变压缩的选项.

我需要做什么来启用压缩,或者只有在天蓝色中使用Vserver时才可以这样做?

Pet*_*ter 6

您可以在web.config中更改此设置:

<system.webServer>
  <urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

然后:

<httpCompression>
  <dynamicTypes>
    <clear />
    <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 />
     <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>
Run Code Online (Sandbox Code Playgroud)

来源:Microsoft论坛

  • 我在Azure Web App上使用与您相同的配置遇到了相同的问题,但似乎无法正常工作。我离开了一段时间,以刷新页面。我想这可能是某个地方的缓存问题。我也从statictypes部分删除了application / json mime类型。我不希望服务器为我提供缓存的版本,因为大多数情况下,它们是从数据库中获取的控制器操作的结果。您可以检查此链接以获取更多信息https://www.iis.net/configreference/system.webserver/httpcompression (5认同)