question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom "Cache-Control" header seems to have stopped being set since May

See original GitHub issue

In 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:open
  • Created a year ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ZYinMDcommented, Jul 22, 2022

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.

1reaction
ZYinMDcommented, Jul 16, 2022

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 both Output Directory and Root 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.

project-root
  |---.vercel/
  |---src/
  |---dist/
  |     |---index.html
  |     |---assets/

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is ASP.NET Core setting cache-control headers on error ...
The ResponseCacheFilter (source) is the action filter that actually sets the Cache-Control headers, but it doesn't take into account status ...
Read more >
What is Cache-Control and How HTTP Cache Headers Work
What is the Cache-Control Header. Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses....
Read more >
Caching Header Best Practices - Simon Hearne
Caching headers are surprisingly complex and often misconfigured. Here we look at some key cache scenarios and recommend the ideal headers ...
Read more >
IIS cache control header settings - Server Fault
HTTP Response Headers -- most likely the place to look after: there may be a custom header setup to explicitly forbids caching .....
Read more >
Cache-Control - HTTP - MDN Web Docs
The Cache-Control HTTP header field holds directives ... should avoid storing personalized contents to be cached in the shared cache.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found