在iis中托管后,在使用webpack 3.10.0的angular 5项目中,Gzip压缩不起作用。我尝试过的插件是[email protected]和brotli-gzip-webpack-plugin。
下面显示的是示例代码,并且插件包含在生产配置中。
const BrotliGzipPlugin = require('brotli-gzip-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
plugins: [
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.(js|html)$/,
threshold: 10240,
minRatio: 0.8
}),
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
})
]
}
预计将加载较小尺寸的文件,并包含类似于内容编码的内容:响应标头中包含gzip。
这是我的构建的外观,它也包含gzip,brotli文件。
通过ASP.Net核心提供压缩文件时,需要使用CompressedStaticFiles中间件。
地方app.UseCompressedStaticFiles();
,而不是app.UseStaticFiles();
在Startup.Configure().
如果浏览器支持,它将确保您的应用程序将提供预压缩的gzip和brotli压缩文件。
有关详细信息,请参阅brotli-gzip-webpack-plugin。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句