Gzip compression doesn't work in a angular 5 project which uses webpack 3.10.0 after hosting in iis. The plugins I have tried are compression-webpack-plugin@1.0.0 and brotli-gzip-webpack-plugin.
Shown below is a sample code and the plugins are included in production configs.
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
})
]
}
It was expected to load a smaller size of the files and include something similar to content-encoding: gzip in response headers.
This is how my build looks, it has gzip, brotli files as well.
It is needed to use the CompressedStaticFiles middleware when serving compressed files over ASP.Net core.
Place app.UseCompressedStaticFiles();
instead of app.UseStaticFiles();
in Startup.Configure().
This will ensure that you application will serve pre-compressed gzipped and brotli compressed files if the browser supports it.
Refer brotli-gzip-webpack-plugin for details.