Strange cloudflare caching issue only on browsers

I have an api where I cache the get api endpoint in Cloudflare using rules:

Cache Level: Cache everything
Edge cache TTL: 1 month

I invalidate the cache using Clouldflares api (it’s okay if cache is stale for a minute or so). Everything works if I visit the endpoint in the browser (i get the current fresh data). It works if I fetch the endpoint in node using node-fetch. It works if I get the endpoint with postman. So far so good. Works as expected.

However, if I fetch the endpoint using fetch api in the browser (both in my app and by fetching it in the console) I get old data. Very old data (days old so not just that cache hasnt had time to propagate the invalidation).

And of course then I think “must be some kind of browser cache issue” but it seems not because:

  1. Still wrong even if I a) disable cache b) open in incognito mode c) clear all the browser cache.
  2. I get the same issue on other browsers and even other computers that I never visited the endpoint with.
  3. If I turn on Development Mode in Cloudflare to bypass the cache then I get the correct data and as soon as I turn of Development Mode I get the old incorrect data again.

That makes me think it can’t be a browser cache issue (because why would that be affected by turning on and off Cloudflare cache). But I can’t understand how the CF cache can be correct for everything except when fetched using javascript in a browser (directly in browser works as does javascript outside the browser).

Any idea what the issue can be?

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