How To Stop Cloudflare From Caching sitemap Files

Cloudflare is a popular CDN that is used by many people using Infinityfree.

Cloudflare caches your webpages and serves the static pages to visitors instead of fetching the page from the origin server.

If you have set Cloudflare cache settings to “cache everything” then it is in your interest to isolate sitemap.xml from that rule so a new fresh version is served rather than an outdated one (cached).

To do this, go to dash.cloudflare.com and select your domain. Go to the Page Rules tab which looks like this:

Click “Create Page Rule” and set *yourdomain.tld/sitemap* for the URL (replace yourdomain.tld with your domain).

For the “Pick a Setting” field, select Cache Level, and set the “Cache Level” to Bypass.

Finally go to the “Caching” tab and click “Purge Everything” under “Purge Cache”.

Now whenever you update your sitemap file cloudflare will serve it directly without caching.

4 Likes

im not experanced in page rules, but try

yourdomain.tld/*.xml and cache to bypass…?

That will also work, but will not cache all xml files

1 Like

So as long as sitemap.xml is your only xml file, it will work

Also remember to put a * in front of yourdomain.tld/*.xml, ie: *yourdomain.tld/*.xml or else it will not work on all the url variations (http, https, www, non-www).

2 Likes

yeah.

@Dev-I-J

I would ask you to edit and clarify a little more clearly

because CF by default does not cache XML files
Cloudflare caches XML responses only when using Cache Everything.
So in a lot of cases users would do something they don’t need.

the matter is further complicated by various cache plugins for WP which also know to keep a sitemap in the cache

5 Likes

OK I edited the post:

1 Like

@Dev-I-J

Hi

There is no need for you to give me credit and it just distracts people from your tutorial
(thanks but be free to drop that text ) :slight_smile:

Simply write at the beginning something like:

If you have set Cloudflare cache settings to “cache everything”
then it is in your interest to isolate sitemap.xml from that rule
so a new fresh version is served rather than an outdated one (cached).

btw. one small typo yourdoamin.tld

2 Likes

Thanks Again :grinning_face_with_smiling_eyes: I edited the post

2 Likes