Custom "Cache-Control" header seems to have stopped being set since May
See original GitHub issueIn my web app, I aggressively cache some static assets in user’s browsers by setting headers like cache-control: public, max-age=2592000, stale-while-revalidate=31536000
. However, I noticed that in my recent deployments, this header was lost. It fell back to the default cache-control: public, max-age=0, must-revalidate
.
I checked my git history and made sure I never changed my deploy configs, so I suspect something changed on vercel’s side.
I always deploy from cli: vercel --prod --local-config .vercel/vercel.json
. And my vercel.json
is:
{
"headers": [
{
"source": "/assets/:any",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=2592000, stale-while-revalidate=31536000"
}
]
}
]
}
I looked though all my deployments over time, and found the last deployment that had the correct header was on 4/24, all deployments before that were good. The first deployment that lost the header was on 5/16, all deployments after that didn’t have the header. So, something changed between 4/24 and 5/16, maybe the vercel cli, or maybe the hosting server.
I may have upgraded my vercel cli during that time, but I can’t pinpoint the date.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (5 by maintainers)
I noticed that this issues seems to have been fixed, the fix happened somewhere between 2022-07-22 and 2022-07-17. It seems to have happened on the hosting server and no upgrade to vercel CLI was needed.
I found the answer - it has to do with the setting of
dist
folder.Because I host a simple static website and I build locally, I don’t need vercel to build for me in the cloud, so I set
build command
to""
, then set bothOutput Directory
andRoot Directory
to"dist"
. It may look weird, but I think it makes sense, because vercel doesn’t need to worry about anything outside of my locally bundled dist folder.This has been working fine until May, then I believe there had been a regression - it still deploys ok, but my
headers
config doesn’t work anymore.Anyway, I found that if I change
Root Directory
to"./"
, this issue is fixed.