简体   繁体   English

如何在 angular7 中为生产提供 gzip 压缩文件

[英]How to serve gzip compressed file on production in angular7

var BrotliGzipPlugin = require('brotli-gzip-webpack-plugin');
module.exports = {
    plugins: [
        new BrotliGzipPlugin({
            asset: '[path].br[query]',
            algorithm: 'brotli',
            test: /\.(js|css|html|svg)$/,
            threshold: 10240,
            minRatio: 0.8
        }),
        new BrotliGzipPlugin({
            asset: '[path].gz[query]',
            algorithm: 'gzip',
            test: /\.(js|css|html|svg)$/,
            threshold: 10240,
            minRatio: 0.8
        })
    ]
}

I am using this code but couldn't able to serve the compressed file on production mode and also using Apache server.我正在使用此代码,但无法在生产模式下提供压缩文件,也无法使用 Apache 服务器。

There really isn't enough code here to provide a definitive answer, I think ... but here's where I would start looking: "in the client-side browser logs."我认为这里确实没有足够的代码来提供明确的答案……但我会从这里开始寻找:“在客户端浏览器日志中”。 You should see an HTTP request going out, and a GZIP-encoded reply coming back with the HTTP header tag Content-Encoding: gzip .您应该看到一个 HTTP 请求发出,一个 GZIP 编码的回复返回,带有 HTTP 标头标记Content-Encoding: gzip

Well, do you see the request going out?那么,看到的要求要出去吗? Was the return-code 200 OK ?返回码200 OK吗? Was the encoding specified?是否指定了编码? What did the client-side browser actually do?客户端浏览器实际上做了什么? Unfortunately you tell us none of these things.不幸的是,你没有告诉我们这些事情。

(Also be mindful that many browser exchanges use gzip encoding routinely for everything. The algorithm's so fast that it's basically free ...) (还要注意,许多浏览器交换通常对所有内容都使用gzip编码。该算法非常快,基本上是免费的......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM