Getting the Most out of a Free Cloudflare Account

By default, Cloudflare does not cache HTML files. If like me, your traffic is > 50% HTML, that is not making the most of your account. Also, if like me you use WordPress, the HTML pages are slow to create and place a heavier load on your hosting server than a few static images, and css and javascript files. This can result in an analytics graph like the following, with most traffic uncached.

Screenshot from 2015-11-09 15:06:16

So to get around this you need to set two custom page rules in Cloudflare. Go here to do that:

Rule 1: Pass-through for Admin

First set up a rule allowing access to your WordPress admin interface (adjust for the admin panel of your own content management system if using something different):

Use this as the URL pattern (the first field of the form):*

Adjust the URL to match your own site. Then go through the other fields and turn off all caching. This rule will override the settings for the rest of your site and let you through to change it without caching getting in your way.

Rule 2: Cache Everything Else

Now make a second rule to be an aggressive default. Use this as the url pattern, to match every page on your site:


Then set the custom caching drop-down to `Cache everything`. That will let all the static and dynamic HTML pages also be cached in Cloudflare servers all around the world. Now your visitors will be pulling compressed versions of your pages with all the optimisations that Cloudflare apply from the servers closest to them. The result should be a graph more like the one below with lots of cached traffic shown as the orange trace here.

Screenshot from 2015-11-09 15:07:55

Edit, 19th July, 2017

Just to check the page rules are working I ran a little wget job (with sensible random waits) on this site repeatedly. I configured wget to only request html pages, not images, css, etc. On the left below we see Cloudflare caching the html pages while undergoing this repeated site mirroring.
Cloudflare caching html pages under repeated site mirroring.

Just to confirm it is these rules that make the caching of HTML work I reran the experiment with the page rules disabled The mirroring of html causes a big spike in uncached traffic in this case, as shown on the left below.
Cloudflare uncached traffic spike when page rules allowing html caching are disabled and the site is repeatedly mirrored.
These two experiments show that Cloudflare doesn’t cache HTML by default but you can easily force it to do so with the simple page rules given above.

This strategy can let you run a high-traffic site off a cheap shared hosting provider. Why not try setting up a website with Bluehost or 1and1 and then turning on Cloudflare with these rules for yourself?

TAGS > , ,

  • Florian

    Interesting approach. But let’s say you browse your blog while you’re logged in: wouldn’t cloudflare cache the article you just published with you being logged in with all the meta stuff loke “edit article” and so on for everyone to see?

    • Andrew

      I see what you are saying there. From a little test I just did with an incognito browse, not visually, no, and of course the random visitor would not actually be logged-in and so would be unable to do anything with the dashboard gui if it did show. Please let me know if you spot any information leakage that could be an attack vector.

  • MakeOnlineShop

    Hello, are you sure that you can force cloudflare to cache everything so easily ?!

    • Andrew

      I think so. I’m mirroring this site in a loop ATM to check this is all still working.

    • Andrew

      See the results of the loop in the edit above. HTML caching is working.


Post a comment