如何防止第三方应用程序(例如 Internet Download Manager)下载预 gzip 压缩的文件?

问题描述 投票:0回答:2

我需要将我的 React 项目压缩为

gzip
文件,以便在生产模式下获得更好的性能。所以我用
compression-webpack-plugin
压缩了我的反应文件,与下面的
webpack.config
相同:

 plugins: [
        new CompressionPlugin({
            algorithm: 'gzip',
            test: /\.(js)$|\.(css)$|\.(html)$|\.eot?.+$|\.ttf?.+$|\.woff?.+$|\.svg?.+$/,
        })
    ],

这是输出文件夹:

我正在使用 Url 重写器加载服务器上的

pre-gzip
文件,而不是
js
上的原始
web.config
文件:

  <rewrite>
      <outboundRules  rewriteBeforeCache="true">
          <rule name="Custom gzip file header">
              <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern=".*" />
              <conditions>
                  <add input="{REQUEST_URI}" pattern="\.gz$" />
              </conditions>
              <action type="Rewrite" value="gzip"/>
          </rule>
      </outboundRules>
      <rules>
          <rule name="Rewrite gzip file">
              <match url="(.*)"/>
              <conditions>
                  <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" />
                  <add input="{REQUEST_FILENAME}.gz" matchType="IsFile" />
              </conditions>
              <action type="Rewrite" url="{R:1}.gz" />
          </rule>
      </rules>
  </rewrite>

此外,我还在我的操作系统上安装了 Internet Download Manager。我的问题是互联网下载管理器,

gz
文件下载器,导致网站需要修复!这是问题的图片:

如何才能不让第三方应用程序(例如 Internet Download Manager)停留在从服务器发送的响应和想要接收它的客户端之间,并且

gzip
文件正常工作?

reactjs webpack iis web-config gzip
2个回答
1
投票

我认为您提出了错误的请求,您应该向

vendor.js
发出请求,而不是
vendor.js.gz
(可能在您的 HTML 中)。我从未使用过 IIS,但服务器应该配置为如果它获取请求标头
Accept-Encoding: gzip
,则它会传递响应标头为
Content-Type: gzip
的 gzip 压缩文件。

例如,如果您查看 StackOverflow 请求,它会获取一些响应标头为

.js
Content-Type: gzip
文件。这告诉浏览器应该首先解压缩内容。

正如您在图像中看到的,这只是对

.js
文件的请求。


0
投票

以下步骤可能会有所帮助:

  1. 在 Internet 下载管理器中,打开选项;
  2. 选择文件类型;
  3. 您可以编辑文件类型(例如 GZ、GZIP)或编辑不自动开始下载的站点列表

© www.soinside.com 2019 - 2024. All rights reserved.