Skip to content

Instantly share code, notes, and snippets.

@rained23
Created October 13, 2020 04:21
Show Gist options
  • Save rained23/769b3e0f8c1fcca292a7ffbf78de783a to your computer and use it in GitHub Desktop.
Save rained23/769b3e0f8c1fcca292a7ffbf78de783a to your computer and use it in GitHub Desktop.
nextjs cache control
app.prepare().then(() => {
const server = express();
if (env.NODE_ENV === "production") {
server.get(
/^\/_next\/static\/(images|fonts)\//,
(_, res, nextHandler) => {
res.setHeader(
"Cache-Control",
"public, max-age=31536000, immutable",
);
nextHandler();
},
);
}
// ...
handle(req, res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment