与下一个JS的快速静态GZIP

发布于 2025-01-17 09:44:23 字数 965 浏览 3 评论 0原文

我有一个带有自定义服务器的 next.js 应用程序。 我看到 next.js 已经有 gzip 压缩。但我也想添加 brotli 压缩方法。 我连接两个库进行压缩。 brotli-webpack-plugincompression-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文