The default cache-control header has a heavily negative impact on my web app. Content is generated dynamically as you navigate through the app. Images are constantly being reused but without cache they involve a delay which is clearly noticeable.
This slows down navigation a lot and is not acceptable. But it should be ok because you can change the header. So I set this netlify.toml:
[[headers]]
for = "*"
[headers.values]
cache-control = "public, max-age=600"
That works like a charm for a while. But after a few minutes Netlify goes back to serving the default header and the annoying experience comes back with it.
After a lot of testing I finally found the reason.
Netlify ignores the cache-control header configuration for 304 responses (etag matches) and ALWAYS sends the default one. This is extremely annoying since I already distributed the link though Netlify and it makes the apps look a lot slowerâŚ
Weâre still working on this case in the helpdesk with you and the team will be able to reconsider your results next week when we have some bandwidth. Weâll follow up in community too once we come to some conclusion.
@luiscastro193, Iâve followed up with in our helpdesk ticket. It looks like our system parses custom headers in a case sensitive way. As a workaround, I have suggested defining the header like so:
Ah ok. It looks like a new issue then. Iâll get that filed as well and will update here if and when we get a fix deployed. Unfortunately, I donât have a workaround for it at this time.
Edit: Actually, checking the page a few minutes after initial deploy, images are flickering again. For some reason, the headers settings in netlify.toml donât seem to stick for long.
304 responses go back to default Cache-Control, leading to noticeable flickering when navigating between pages that use the same image files.
The issue is jarring when using Firefox, less so when using Chrome.
As a workaround, Iâve added the following settings to my netlify.toml - this removes the flickering, with max-age being short enough to invalidate content quickly.
Ideally, we probably wouldnât have to use this settings, so adding this comment for future reference and to be kept in the loop regarding updates
[[headers]]
for = "*.jpg"
[headers.values]
Cache-Control = "public, max-age=300"
[[headers]]
for = "*.png"
[headers.values]
Cache-Control = "public, max-age=300"
@MatsLanGoH, we appreciate your thoughts on this. We will update this topic if/when the behavior is corrected. Also, please feel free to âwatchâ this topic (there is a button below) if you want to receive emails about any updates here.
Last but not least, welcome to our community site!
I replied in the topic you linked to above. I believe the issue you are experiencing is unrelated to the 304 status issue.
The issue filed for the 304 responses not sending custom headers remains open. It is not resolved at this time. (Again, though, I donât think it is the root cause of the issue you are seeing.)
A fix for this issue would be appreciated.
For development purpose, we need to totally disable cache management on server-side, but this â304â behaviour breaks our application
Sorry, we donât have an update yet. However, looking at your thread, it does look to be the same 304 issue so youâll want to keep an eye on this thread. Weâll update this thread once weâve resolved the issue. Thank you for your patience.
The weird thing is, there werenât any problems with the cache-control header until a few days ago. When I checked it at least 4 days ago (right after the last build), it definitely worked.
The caching issue was discovered exactly 10 minutes ago from now.
Thank you for sharing this with us. Unfortunately, I do not have an update or an ETA on this. As Dennis mentioned above, we will update this thread once the issue is resolved.
Was this issue already resolved? I have the same (a similar?) issue on my site:
When reloading, the images are always refetched ignoring the cache settings, even when navigating back and forth. I have tried to change the cache headers with the netlify.toml:
Iâm interested in this issue as well, since I was troubleshooting why my cache-control headers werenât working for over an hour; I double-checked whether I was writing my rules correctly in the Netlify Playground, I split out my glob into multiple individual sections, and I added a custom x-does-this-work="true" header on the off-chance it was a problem with cache-control specifically.
But IG itâs just that we need a method to set custom headers per response code?
Would it be possible to borrow from the redirects syntax?
ex:
[[headers]]
for = "/*"
status = "304"
[headers.values]
Cache-Control = "public, max-age=0, stale-while-revalidate"