当前位置:首页 > 服务器技术 > IIS

javascript – Angular的PRE-Gzipped文件不是通过IIS提供的吗?

我准备了所有的设置(在我家,Windows 10)来创建和提供js作为gz文件,但仍然 – 我只获得常规的js文件(原始大小).

Configuration

– Angular的webpack文件:

new CompressionPlugin({
      asset: "[path].gz[query]",
     algorithm: "gzip",
     test: /.js$|.css$|.html$/,
     threshold: 10240,
     minRatio: 0.8
 })

– 该配置的输出文件:

– Index.html文件:

...
<body>
  <app-root>Loading...</app-root> 
  <script src="/dist/polyfills.bundle.js"></script>
  <script src="/dist/main.bundle.js"></script>
</body>
...

Diagnostics

当我导航到http://kkk.com/index.html时,我会获得完整大小的文件:

另外 – 查看请求标头,我发送Accept-Encoding:gzip,deflate标头:

为什么不提供GZ文件?

附加信息 :

>没有304回复,我设置了.
>在我的工作中,Windows 7,相同的文件 – 我做(!)看到gziped文件:

>禁用防病毒软件
>权限:每个人:完全控制文件的文件夹.
>请求标头之间的比较:

>因为我不想要实时压缩,但是PRE-ZIPPING(已经通过角度gzip压缩的文件) – 我尝试启用AND禁用压缩(只是为了看它是否会影响某些东西 – 但它没有 – 我仍然很大文件):

解决方法:

好.经过大量搜索 – 我已经设法使用URLREWRITE和一些IIS配置.

首先 – 我禁用了这个:

因为我这里不需要CPU.我已经有了预压缩文件.

好的 – 这里的关键是这两个部分:

1)将contentType设置为application / javascript
2)将contentEncoding设置为gzip.

所以我写了这两个urlrewrite规则:

第一部分是将所有js文件重写为js.gz,第二部分是outboundrule用于添加带有gzip值的内容编码头.

这是配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="https" enabled="true" stopProcessing="false">
                    <match url="(.*).js" />
                    <conditions></conditions>
                    <action type="Rewrite" url="{R:1}.js.gz" appendQueryString="true" logRewrittenUrl="true" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="Rewrite content-encoding header" preCondition="IsGZ" stopProcessing="false">
                    <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern=".*" />
                    <action type="Rewrite" value="gzip" />
                </rule>
                <preConditions>
                    <preCondition name="IsGZ">
                        <add input="{URL}" pattern=".gz$" />
                    </preCondition>


        </preConditions>
        </outboundRules>
    </rewrite>
    <urlCompression doStaticCompression="false" />
</system.webServer>

只需将其粘贴到web.config文件中即使您不使用Asp.net也是如此.

另外 – 你必须将它添加到mime类型:

现在,正如您所看到的那样,我确实得到了正确的大小:

更深入:

这是我预先设定的那个:

就这样.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!