Question about the 'origin' header

Hello everyone!

I’m having some problems with a cached asset. It serves the latest version when I visit the URL in the browser, but I get an older version when I request it using AJAX.

I investigated a bit more and found that the problem seems to be with the ‘origin’ header. To illustrate this problem with CURL commands:

Serves the correct (latest) asset:
curl 'https://teclia.io/api/forms/2364bf04-a6ea-494c-a157-be06128b761a'

Serves an older version:
curl 'https://teclia.io/api/forms/2364bf04-a6ea-494c-a157-be06128b761a' -H 'origin: http://localhost:5000'

Notice the content of the first request is much smaller.

Maybe I missed some configuration in the page rules? Or is it a problem specific to ‘localhost’?

Thanks for your time!

The issue seems to be the same described here: Problem with AJAX and cache

The author have decided to disable the CDN cache to solve this. If anyone has an alternative, that would be much appreciated!

I forgot to mention, but just like the other topic’s author I’m manually purging the cache when the content changes using the ‘Purge individual files by URL’ API.

Thanks!

You have three options here:

  • Use a Page Rule to not cache those ajax urls.
  • In your script, append a random url variable to the ajax request.
  • Use POST instead of GET for the ajax request. That’s slower though.

The origin header is part of the cache key, so what this means is you likely need to purge the URL with the origin header - this can be done via our Purge API - see Option 2 in the KB below:

https://support.cloudflare.com/hc/en-us/articles/203063414-Why-can-t-I-see-my-CORS-headers-

That was it!

Thanks for the help :smiley: :smiley: :smiley:

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