I’m having a big problem (2 entire days trying to solve) with AJAX requests (xhr) and Cloudflare cache.
I’m caching a JSON API with Cloudflare, everything works good from browser URL and from Postman, but with AJAX from my JS script, Cloudflare is returning an purged cache version of the file.
The JSON is update (was purged from Cloudflare API), acessing the URL directly from browser it returns the expected content, but from AJAX it returns an older version.
I’ve tried many things with page rules, but nothing works as I want
I’m sure that I’m testing the same URL, and I’m sure that it’s not the browser cache (checked thousand times at console).
My cache header:
Cache-Control: public, max-age=5, s-maxage=2592000, stale-if-error=31536000
Other note, when I change the cache level to bypass the response with AJAX is the expected, but when I turn back to cache everything the problem happens again (only with AJAX).
Does anyone knows why is it happening? Some idea to solve (if there is a way to solve)? Thanks a lot!