Next.js Discord

Discord Forum

Override cache-control header for prefetch requests?

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hey all, using Next.js 13.4.11 - All of the prefetch requests that are created have a cache-control s-maxage of 31536000 (1 year) which isn't ideal in my situation.

I'm wondering if it's possible to override it somehow? I though I might be able to do this either in next.config.js or server.js, but when the site is deployed, it always reverts to 31536000.

In server.js I tried to adjust the header by using res.setHeader('cache-control', '5') before the handle takes place. This works if I run the site locally with npm run start, but not when I deploy the site to it's hosting location (Azure).

I've read that Next.js sets this s-maxage for assets such as CSS and JS, but I feel it's abit overkill for the json prefetch data. Hence the reason I'd like to amend it.

0 Replies