express-static-gzip with next js

Viewed 651

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.

0 Answers
Related