Angular的PRE-Gzipped文件不能通过IIS提供? [英] Angular's PRE-Gzipped files are not served via IIS?

查看:104
本文介绍了Angular的PRE-Gzipped文件不能通过IIS提供?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备了所有设置(在我家,Windows 10),用于创建和提供 js gz 文件,但仍然 - 我只获得常规 js 文件(原始尺寸)。

I have prepared all the settings (at my home , Windows 10) for creating and serving js as gz files , but still - I get only the regular js files (with the original size).


配置

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 时,我得到了全部大小文件:

When I navigate to http://kkk.com/index.html , I get the full size files :

另外 - 查看请求标题,我发送接受编码:gzip,deflate 标题:

Also - looking at the request headers , I do send the Accept-Encoding:gzip, deflate header :

问题

为什么不提供GZ文件?

Why doesn't the GZ files served ?

其他信息:


  • 没有304回复,我设置了。

  • 工作,windows 7 相同文件 - 我做(!)看到gziped文件:

  • There is no 304 responses , I set .
  • At my work , windows 7 , same files - I DO(!) see the gziped files :


  • 已禁用防病毒

  • 权限:所有人:对文件文件夹的完全控制。

  • 请求标头之间的比较:


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

推荐答案

好的。经过大量搜索 - 我已经设法用 URLREWRITE 和一些IIS配置。

OK. After searching a lot - I've managed to do it with URLREWRITE and with some IIS configuration.

第一 - 我已禁用此功能:

First - I've disabled this :

因为我不喜欢这里不需要CPU。我已经预先压缩文件。

Because I don't need CPU here. I already have the pre zipped files.

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

OK - the key here is those two sections:

1)将 contentType设置为 application / javascript

2)设置 contentEncoding 到gzip。

1) Set contentType to application/javascript
2) Set contentEncoding to gzip.

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

So I've written these 2 urlrewrite rules :

第一部分是将所有 js 文件重写为 js。 gz ,第二条规则是 outboundrule 用于添加内容编码标头 gzip value。

The first section is to rewrite all js files to js.gz and the second rule which is an outboundrule is for adding the content encoding header with gzip value.

这是配置文件:

<?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>

只需将其粘贴到网络上.config文件(即使您不使用Asp.net)。

Just paste it in the web.config file (even if you don't use Asp.net).

此外 - 您必须将此添加到mime类型:

Also - you have to add this to the mime types :

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

Now , as you can see the response I do get the right size :

更深入:

我预备的那个是:

这就是全部。

这篇关于Angular的PRE-Gzipped文件不能通过IIS提供?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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