How to avoid caching 404

I see many post about how to avoid caching 404, and most will be replied with this article as a link, meanwhile pointing out that a 404 should be cached only for 3 minutes.

But this is not true.

Some of our users can not load our website for some js files hit the 404 cache, even one day later after they feedback the issue. We have to purge the 404 cache files which is annoying because there are many js files and we do not want to purge all our resources.

I don’t know why the 404 caches are not expired after 3 minutes like the official document’s statement. Maybe because I set the page rule and set the Edge Cache TTL one month? I did not set any cache info in the response header.

So could anyone please provide a way to avoid cache 404 for long time? For our website is built with react, if the js file is missing, the website can not load normally.

Thanks very much.

I’d rather doubt that.

Can you provide a 404 link which comes from the cache?

Did you pay attention to

when no cache-control directive or expires response header are present:

Just checked it and a cached 404 expires after three minutes.

Thanks for your quickly reply. It’s not for all regions, now it’s for our Hungary users. Other country users should not have this issue.

For the user can access our website normally. I just access the 404 file directly in the browser with Hungary VPN, and clear the disk cache.

For now, I don’t purge this file from the cache dashboard. But I think the cache should be refreshed.

If you has Hungary VPN, you can check whether you can access this url normally:

That would suggest a datacentre specific issue, which is rather unlikely. Most likely they might have some issues with the 404s cached by their browsers.

The URL you provided does not return a 404 for now. Can you provide such a link?

Thanks for your suggestion. I have checked this after more than two hours before I put the 404 js url directly in the browser.
The result is always hit 404 cache.

Which is the 404 URL?

Also, provide the output of

1 Like

The 404 url is But just like I said, now with my Hungary VPN, I can access this file normally (Hit 200 cache).

Seems to load everywhere fine

But if you say you currently don’t experience the issue it is hard to debug. Either there is a browser caching issue or your server sends response headers which instruct Cloudflare to cache longer.

By default Cloudflare caches only for three minutes as confirmed earlier.

1 Like

OK, Thanks very much for your time. I totally understand the difficulties for no online case.

Next time I will put the issue first here before I resolve it. I will keep this issue open.

It is not so much an issue, rather a simple thread :wink:

Yes, please keep it reproducible, otherwise it is impossible to debug. Also check any caching headers your server might send.

1 Like

I can confirm that it stays longer than three minutes in the cache in your case, but that is datacentre independent.

That could be either a page rule you set up or it will be aforementioned caching header from your server.

1 Like

Thanks for your information. I will try to reproduce it and come back here. Then we can check the real reason.

The reason will be as just mentioned :wink:
Check these two.

Hi sandro, with a new computer, I reproduce it with Hungary VPN, you can see the HIT status is also 404.

Any suggestion about this? I am definitely sure that I do not set any cache info in the response header.

Ehm, what I have been saying for several postings now?

And yes, the issue has been confirmed a while ago.

I mean what’s the next I need to check. My cache setting is simple:

Browser Cache TTL: a year, Edge Cache TTL: a month

The page rule seems to set that value for 404s as well. Try disabling it, then purge the cache, and try again.

Yes, the page rule is for all the static files. I can purge the cache without disabling the page rule. I just want to know why the 404 cache not expired in 3 minutes?

I just explained that in my previous response and suggested what you should do to test that theory ;).

1 Like