[email protected]
[email protected]
I've noticed that the production version of next.js app with the new next-css does not leverage max-age=31536000 header. This creates redundant round trips when opening a website that has already been loaded previously.
Here's a temporary workaround I'm using in my server.ts:
if (env.NODE_ENV === "production") {
server.get(
/^\/_next\/static\/css\//,
(_, res, nextHandler) => {
res.setHeader(
"Cache-Control",
"public, max-age=31536000, immutable",
);
nextHandler();
},
);
}
Not setting max-age to css resources was justifiable before https://github.com/zeit/next-plugins/pull/228, because CSS url could remain the same between builds. However, it seems that infinite caching of CSS can be finally done as the path is now /_next/static/css/commons.HASH.chunk.css.
This is a good workaround. I think there are many users using css that don't realize their css isn't cached by cdn or browser because of this. Hopefully the bug will be fixed for real soon.
Might be still open – see
https://github.com/zeit/next.js/pull/5675#issuecomment-438845063
Most helpful comment
This is a good workaround. I think there are many users using css that don't realize their css isn't cached by cdn or browser because of this. Hopefully the bug will be fixed for real soon.