Netlify ignores cache-control for 304

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.

Why? How can we solve this?

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…

I need some kind of solution please

Hi Luis,

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:

Cache-Control = "public, max-age=600"

Can you confirm if this works for you?

It doesn’t: https://sleepy-dubinsky-4ed592.netlify.com/

As always 200 responses are fine but 304 responses go back to the default Cache-Control.

This is the config file: https://github.com/luiscastro193/graph/blob/master/netlify.toml

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.


I can confirm the same issue with our demo site - currently evaluating Netlify / NetlifyCMS for our company site at https://loving-pasteur-90ee68.netlify.com/

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 :slight_smile:

[[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! :slightly_smiling_face:

1 Like