robinrajanic_
robinrajanic_
KPCKevin Powell - Community
Created by robinrajanic_ on 3/15/2024 in #front-end
Performance
Should we use next-gen image format for poster attribute? or do they have any fallback?
4 replies
KPCKevin Powell - Community
Created by robinrajanic_ on 12/6/2023 in #front-end
Brotli compression in next.js
Hey guys I'm working on brotli compression in next.js and I need your help Problem: The compression works fine, I can see the [filename-hash].js.br files in the _next/chunks. But when doing npm start, the production build doesn't have the .br chunk files. Next.config.js
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback.fs = false;
config.resolve.fallback.tls = false;
config.resolve.fallback.net = false;
config.resolve.fallback.child_process = false;
}
config.plugins.push(
new BrotliPlugin({
asset: "[path].br",
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8,
})
);
return config;
},
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback.fs = false;
config.resolve.fallback.tls = false;
config.resolve.fallback.net = false;
config.resolve.fallback.child_process = false;
}
config.plugins.push(
new BrotliPlugin({
asset: "[path].br",
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8,
})
);
return config;
},
middleware.js
// This part contains error i guess (Start)
if (nextUrlPathname.includes("_next/static/")) {
NextResponse.rewrite("*.js", (req, res, next) => {
req.url = req.url + ".br";
res.set("Content-Encoding", "br");
res.set("Content-Type", "application/javascript; charset=UTF-8");
next();
});
}
// This part contains error i guess (End)
// This part contains error i guess (Start)
if (nextUrlPathname.includes("_next/static/")) {
NextResponse.rewrite("*.js", (req, res, next) => {
req.url = req.url + ".br";
res.set("Content-Encoding", "br");
res.set("Content-Type", "application/javascript; charset=UTF-8");
next();
});
}
// This part contains error i guess (End)
Note: I'm using next.js version 13.4.6, and I'm NOT using app router. And i don't need server.js or node.js suggession. Just wanted to handle it in NextRequest and NextResponse itself. (Thanks In Advance)
2 replies