我们是否需要手动设置Nuxt发送压缩或brotli压缩的文件?

A.P*_*nko 2 gzip webpack brotli nuxt.js

为了提高灯塔得分,我需要启用gzip和/或brotli压缩,以便提高性能得分。我在nuxt.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
    })
  ]
Run Code Online (Sandbox Code Playgroud)

我可以确认,在添加这两个插件实际上是创造.gz.br我的文件版本。

主要问题是:为了发送这些压缩文件,我是否应该对我的nuxt配置文件做一些额外的操作,否则nuxt会自行处理?是否可以检查localhostbrotli例如,因为我已经读过,仅适用于HTTPS协议)?

PS我不使用任何框架expressrestify

Ald*_*und 5

如果您使用的是nuxt 2,则可以更轻松地完成。

import shrinkRay from 'shrink-ray-current'

export default {
  render: {
    compressor: shrinkRay()
  }
}
Run Code Online (Sandbox Code Playgroud)

请参阅本文了解摩尔定律https://blog.lichter.io/posts/nuxtjs-on-brotli