Azure WebApp简单的Html / JS gzip

时间:2017-09-01 14:00:01

标签: azure gzip azure-web-sites

尽管已多次询问我仍然没有在StackOverflow上找到一个可行的解决方案:

我用角度cli创建了一个角度SPA。这给了我.html / .js文件,我已经部署到azure。 现在我想让azure为gzip编码的这些文件提供服务。 为此,我创建了一个web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <httpCompression
              directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
           <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        </httpCompression>
        <urlCompression doStaticCompression="true" doDynamicCompression="false" />
    </system.webServer>
</configuration>

但是这并没有为gzip压缩任何文件。

我也尝试过这个配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <urlCompression doStaticCompression="true" doDynamicCompression="false" />
        <httpCompression>
            <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/x-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>
</configuration>

同样的结果......

有谁知道如何让azure为这些静态文件gzip服务?

2 个答案:

答案 0 :(得分:0)

您是否尝试过进行XDT转换?如下所述:  https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/foo" enabled="true" xdt:Transform="Insert" />
      </dynamicTypes>
    </httpCompression>
  </system.webServer>
</configuration>

答案 1 :(得分:0)

我也没有很多运气来支持GZip压缩。我最终做的是获取我的静态Angular文件,将它们放入.NET包中,将计算的哈希附加到URL以进行缓存清除,然后将它们推送到Azure CDN中。我能够让CDN使用GZip压缩来提供文件。