与下一个JS的快速静态GZIP
我有一个带有自定义服务器的 next.js 应用程序。 我看到 next.js 已经有 gzip 压缩。但我也想添加 brotli 压缩方法。 我连接两个库进行压缩。 brotli-webpack-plugin、compression-webpack-plugin 并将其添加到我的 next-config.js 中,如下所示
webpack: (config) => {
config.plugins.push(new CompressionPlugin({
algorithm: "gzip",
test: /\.(js)$/
}))
config.plugins.push(new BrotliPlugin({
asset: "[file].br",
test: /\.(js)$/
}))
return config
},
然后我已经有了构建下一个应用程序后我的 .br 和 .gz 文件。
但我正在寻找如何在下一个 js 中提供该文件的方法? 我有自定义 Express 服务器,并且找到 express-static-gzip 库,但我不明白如何提供压缩文件?
我的 .next 目录与构建后的文件位于 project/src/client/.next 中,我想在我的 Express 应用程序中提供所有文件。
app.use('/static', expressStaticGzip('/.next/static/', {
enableBrotli: true,
orderPreference: ['br', 'gz']
}));
我是这样连接中间件的,但是还是不行。
I have a next.js application with custom server.
I see that next.js already has gzip compressing.But I want to add brotli compress method too.
I connect two library for compressing. brotli-webpack-plugin, compression-webpack-plugin and add it to my next-config.js like this
webpack: (config) => {
config.plugins.push(new CompressionPlugin({
algorithm: "gzip",
test: /\.(js)$/
}))
config.plugins.push(new BrotliPlugin({
asset: "[file].br",
test: /\.(js)$/
}))
return config
},
And after that I already have my .br and .gz files after build my next application.
But I looking for the way how can I serve this file in next js?
I have custom express server and I find express-static-gzip library but I don't understand how can I serve my compressed files?
My .next directory with my files after build located in project/src/client/.next and I want to serve all files in my express app.
app.use('/static', expressStaticGzip('/.next/static/', {
enableBrotli: true,
orderPreference: ['br', 'gz']
}));
I connect middleware like this, but it still doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论