The Cloudflare-CDN-Cache-Control header with a HTML response

I have been trying to get a HTML response (without authentication or cookie) to be cached by Cloudflare, even for a short time.

Each time I get ‘dynamic’ back, not ‘hit’. So that indicates Cloudflare has not cached it.

Reading the docs, it seems by default HTML responses are not cached, even without authentication, and you have to instruct Cloudflare to do that.

So I tried adding the Cloudflare-CDN-Cache-Control header to the response to instruct Cloudflare to cache the page for X seconds. Yet … it doesn’t. It seems. I read the docs (https://developers.cloudflare.com/cache/about/cdn-cache-control) as meaning that if *-CDN-cache-control headers are not present, it would fall back to defaults. So, not caching HTML. Which makes sense. But if they are present … indeed with a Cloudflare- prefix making clear the intention :slight_smile: … it seems that still HTML responses are still not cached.

Do you have to also add a Page Rule? I assume it is the one to enable Origin Cache Control? I can’t see an option for that in the Caching tab, or elsewhere.

If so it would be nice if Cloudflare-CDN-Cache-Control was seen by the proxy and respected for a response. As it can see the headers at the same time it is checking the file extension in the path to decide if it should cache or not. Perhaps there is a technical reason why it can’t.

Thanks.

You need a Cache Everything page rule.

By default, HTML is not cached. Once you add Cache Everything, the the cache behaviour can be managed using the *-Cache-Control headers.

Ah, ‘Cache Everything’. So, not ‘Origin Cache Control’ … ? Or do I need that too?

Its two different things, and you need both.

By default, Cloudflare only caches certain file extensions. If you want to cache other files (such as html) you need to configure Cloudflare to cache those file types. This is the purpose of the Cache Everything page rule.

Once Cloudflare is using the Cache, you need a mechanism to configure the cache behaviour. This can be done using the *Cache-Control HTTP headers.

Yep, I get that. What I wasn’t sure of was the Page Rule for Origin Cache Control. Whether that was needed too.

But it seems not:

Origin Cache Control is enabled by default for Free, Pro, and Business domains and disabled by default for Enterprise domains.

So you only need to set it as on if on an Enterprise domain. As it’s off.

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