Webpack 我们需要手动设置Nuxt send Gzip或brotli压缩文件吗?
为了提高lighthouse分数,我需要启用Webpack 我们需要手动设置Nuxt send Gzip或brotli压缩文件吗?,webpack,gzip,nuxt.js,brotli,Webpack,Gzip,Nuxt.js,Brotli,为了提高lighthouse分数,我需要启用gzip和/或brotli压缩,以便提高性能分数。我在我的numxt.config.js文件中添加了两个webpack插件: plugins: [ new CompressionPlugin({ filename: `[path].gz[query]`, algorithm: `gzip`, test: /\.js$|\.css$|\.html$/, threshold: 10240,
gzip
和/或brotli
压缩,以便提高性能分数。我在我的numxt.config.js
文件中添加了两个webpack插件:
plugins: [
new CompressionPlugin({
filename: `[path].gz[query]`,
algorithm: `gzip`,
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
}),
new BrotliPlugin({
asset: `[path].br[query]`,
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]
import shrinkRay from 'shrink-ray-current'
export default {
render: {
compressor: shrinkRay()
}
}
我可以确认,添加这两个插件实际上是在创建我的文件的.gz
和.br
版本
主要问题是:我应该对我的nuxt配置文件做些额外的事情来发送这些压缩文件,还是nuxt会自己处理?可以在localhost
上检查它吗(因为我读过brotli
,例如,它仅适用于HTTPS协议)
另外,我不使用任何像
express
或restify
这样的框架。如果您使用的是nuxt 2,它可以更容易地完成
在numxt.config.js
文件中:
plugins: [
new CompressionPlugin({
filename: `[path].gz[query]`,
algorithm: `gzip`,
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
}),
new BrotliPlugin({
asset: `[path].br[query]`,
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]
import shrinkRay from 'shrink-ray-current'
export default {
render: {
compressor: shrinkRay()
}
}
有关摩尔的详细信息,请参阅本文