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"
I’m not following what you’re trying. By looking at the toml file, it appears as if you’re trying to set a custom header only when the file is served with a 304 status. Not only this won’t work (as it’s not currently supported), I’m not sure what this will solve.
This is trying to work around a bug in Netlify. According to RFC 7232 The 304 response “MUST generate any of the following header fields that would have been sent in a 200 (OK) response to the same request: Cache-Control, Content-Location, Date, ETag, Expires, and Vary.” Netlify doesn’t do this so @jasikpark is attempting to hack around this by setting the Cache-Control header manually.
It doesn’t make sense to support it either because the RFC says what headers should be present and that they should match the values from the 200 response. Configuring the headers differently is invalid. But it would be nice to get this bug fixed.
I have a similar use case where I’d like to control the caching. Initial request works fine, but it seems the etag is used in requests after a refresh and then I get stuck in a 304 loop.