404s and caching

Hi there,
We’re intermittently encountering an issue where Cloudflare is caching pages that returned 404 HTTP status codes and I’m wondering what the easiest way to deal with this. What happens is:

  1. We start a rolling release of our web app. The release contains some freshly compiled JS files that did not exist in the previous release.
  2. Someone visits our website while the release is running, and their request hits one of the pods with the new code. This code requests one of the new JS files.
  3. This request goes to one of the old pods, which does not have the JS file requested, and returns a 404.
  4. Unfortunately, this 404 response then gets cached by Cloudflare, so even once the release is done, some subset of users hit the Cloudflare cache and get 404s for the file that now exists on every pod.

What is the best way to deal with this? I can switch our code to stop performing rolling releases, but presumably there’s an easier way to prevent pages that return 404s from being cached at all.

404s come from the origin. Do you have a way of configuring the server to set a no-cache header for a 404 response?


I do have control over the origin server. Thanks, I’ll see if I can set that up from nginx.


This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.