How to invalidate headers in the Netlify CDN cache

Site: pronto-web.netlify.app

I’ve been testing out how to pass the correct headers out of Netlify to our CloudFront CDN distribution and I’ve been running into problems where I make the change in the netlify.toml file and that change only shows up sporadically in my responses (presumably depending on which edge node I hit).

If I make an actual change to a file then I do start to get the correct headers. But otherwise I can’t seem to flush out the old headers from the Netlify CDN.

Right now my netlify.toml file’s header section looks like this, but it’s undergone several changes to the cache-control header as I’ve been testing this out over the last couple days:

[[headers]]
for = “/*”
[headers.values]
Netlify-CDN-Cache-Control = ‘’’
public,
maxage=0,
must-revalidate’‘’
cache-control = ‘’’
public,
max-age=58,
s-maxage=120,
must-revalidate’‘’

So, for example, on this URL:

https://cache-headers--pronto-web.netlify.app/images/common/full-image-close.png

When I run curl on it three successive times, I get three different cache-control header values (these are all header values I’ve set at some point in the netlify.toml file, but the current one in the file is: “public,max-age=58,s-maxage=120,must-revalidate”):

cache-control: public,s-maxage=604800,max-age=59
cache-control: public,max-age=58,s-maxage=120,must-revalidate
cache-control: public,max-age=60,must-revalidate

To me it seems like changing the headers section in netlify.toml isn’t enough to invalidate the cached files, I either need to change the actual content of each file, or I need to somehow manually invalidate the CDN cache for all the files.

I looked around for a manual invalidation route and found the Purge API, which I tried a couple times (once with the site_slug and once with my site_id) and both times it reported success. But still the old headers remained. I even waited overnight thinking maybe the CDN cache invalidation was queued up asynchronously, but still I got the same result.

So I guess my core question is: Should Netlify be automatically invalidating the CDN cache for all files when I update the headers? If not, should I use the Purge API to manually invalidate? If so, why is that not working for me?

Thanks for your help,
Ben

Hi, @ben.dolman. I checked every CDN node and they all returned the same header below:

cache-control: public,max-age=57,s-maxage=120,must-revalidate

If you are still seeing this issue, the following information would be helpful:

  • the x-nf-request-id HTTP response header for the incorrect response

Also, if that information is not available for any reason, the information it replaces would instead be:

  • the full URL requested
  • the client IP address
  • the server IP address
  • the date, time, and timezone of the request

If you would either send us the the x-nf-request-id header value or the information is replaces, we’ll research this further. If there are any questions, please let us know.