Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 我们需要手动设置Nuxt send Gzip或brotli压缩文件吗?_Webpack_Gzip_Nuxt.js_Brotli - Fatal编程技术网

Webpack 我们需要手动设置Nuxt send Gzip或brotli压缩文件吗?

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,

为了提高lighthouse分数,我需要启用
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()
  }
}
有关摩尔的详细信息,请参阅本文