Is there a way to cache everything BUT html of a site?

I cannot cache everything on my site since there are a lot of dynamic elements. However, things like images, css, etc. should be cachable without issue.

Is there a way to do this (we’re using the Business version of CF) using Page Rules without risking the HTML being caches as well?

That’s Cloudflare’s default caching approach. Admittedly, Cloudflare is using the file extension (hello, Windows!) rather than the content type, but that shouldn’t matter much.

So, if that’s what you want, you actually don’t need to do anything as Cloudflare is doing that already.


Hi Sandro. Thanks for the reply. Currently I have Page Rules set up to actually EXCLUDE (Bypass) caching for the entire site, and multiple additional rules to allow things like local images (e.g. “…/images/*” and other elements a la carte so to speak. When I allowed CF to cache the entire website by default it did indeed cache dynamic elements in the HTML so perhaps there is a setting I need to make sure I choose, or a single Page Rule I need to set up to make sure no HTML is cached, but everything else is cached?

Again, you don’t need any page rules for what you want. So drop your page rules and the caching should be exactly what you want.

Again, when I allowed CF’s defaults to take control, as I mentioned in y previous reply, certain dynamic elements on the pages were not working properly because CF was caching the HTML of those pages. So unless something changed in the last 12 - 18 months, CF will cache HTML if no Page Rules are set AND CF is left to use the default settings. So, again, I cannot just use the default settings.

Back to my original question, is there a way to do this (we’re using the Business version of CF) using Page Rules without risking the HTML being caches as well (because for our use case, using CF’s default caching settings does NOT work)

For the third time :wink: Cloudflare does not cache HTML

You said you used page rules to cache everything and that is of course the issue. So again, drop all your page rules and it should work fine. If it does not, post the domain after you have dropped the page rules.

Hi Sandro. I did as you suggested and removed all of the existing rules and at first it didn’t cache anything. I then created a single rule for the entire domain set to “Standard” and it seems to have started working now. I checked a few HTML pages and they still show Dynamic, so this seems to be working as well so thanks for your persistence. I’m not sure if perhaps something changed since we first tested this several years ago, or maybe this is different under the Business plan, which is what we’re under now (we were under the Pro when trying this last time). Regardless, I hope this is the answer and thank you for your advice!

A follow up question, however, I noticed CF is only caching our hosted images, but we also pull images from Amazon S3. The buckets are set to Public so the URLs of the images themselves are all public. Any idea how to force CF to cache those images as well since they make up the majority of the images across our site?

Cloudflare can’t cache images from S3 unless you are pulling images through Cloudflare, in which case it should be caching automatically.

Cloudflare can only cache content that is using Cloudflare nameservers. The default S3 URL is using AWS as it’s proxy and can’t be cached without doing stuff on AWS’ side.

No worries, but as I mentioned, you actually don’t need a page rule.

As for the other question, Cloudflare can only cache files which load via the proxies, which your Amazon URLs won’t.

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