Cloudflare is a pretty amazing service, and probably the only on that I know of with a free reverse proxy setup. For most website owners, its value comes from the caching service for static assets by default. I personally also use its DNS servers since I find their response times far faster than those used by my web host.
As just mentioned, Cloudflare automatically caches your JS, CSS, “woff” files (fonts) etc. You don’t need to explicitly specify this. These files are chosen for two very good reasons:
- They are static and don’t change often
- They are requested on almost all page loads for your site
Once these assets are in Cloudflare’s cache, you can use webpagetest.org to see how fast they load compared to the loading speeds from your own origin server. It’s not even close:
All of the assets in the screenshot are cache “hits” on Cloudflare. You can see that it takes between 43 to 69 milliseconds to search each resource. That’s very small. Most likely your origin server clocks in with several hundred milliseconds.
So “Cache Everything”?
This leads one to wonder why we simply don’t cache everything on Cloudflare instead of just static content. In its “Page Rules” section for example, we can force Cloudflare to cache the contents of all requests using the page rule:
Here, we tell Cloudflare to cache everything for 1 month (the maximum allowed).
This means that all of our web pages will be served from Cloudflare’s EDGE caches all over the world right? In fact, our origin server won’t even be touched! Right?
Not so fast.
“Cache Everything” Doesn’t Work Like You Think
Unfortunately, this simplistic page rule causes more problems than it solves. At best, it slows down your site. At worst, it actively harms it. Here’s why.
You’ll Show Admin Pages to Your Visitors
Even relatively static websites don’t show the same page to all their visitors. A prime example is logged in and logged out users. On WordPress sites for example, a lot of users have the Jetpack plugin which adds an admin bar when you’re logged in.
If you happen to visit a page on your site before anyone else, Cloudflare will cache that and show subsequent visitors the logged in version with the admin bar!
Now Cloudflare has an option to bypass the cache with a cookie. This would work great, except that it’s only available to Business users for $200 a month per domain!
Having said that, there are ways to disable the Cloudflare cache when you’re a logged in user. I’ll explore some methods in another article.
You’ll Slow Down your Site
The first hit to an EDGE cache is always a tad bit slower than a direct request to the origin server. That’s because the EDGE server needs to make the request to the origin server anyway in order to cache it for later. Cloudflare has 158 EDGE locations. That means each page of yours will have to be requested at least once from each of these EDGE locations to be completely cached everywhere.
If you have 100 pages on your site (a modest number), that means your site has to be pinged 158*100 = 158,00 times for it to be complete cached. And that’s assuming each request comes from a different combination of page and EDGE server!
The Content Won’t Be Cached
To make matters worse, all CDNs have some form of selective cache purging. If a resource is requested only infrequently, it will probably be removed from the cache and the server will request it again from the origin.
This means that pages which are infrequently visited will almost never get a hit on the EDGE cache. Even if they do get cached, they’ll just drop away at once.
Any Changes Will Reset the Cache
Finally, anytime you make the smallest change to your HTML, the entire cache will reset. It’s terrible!
Bottom line: Cloudflare’s free “Cache Everything” option looks seductive, but it just doesn’t work. Even if you manage to avoid showing admin pages to your users, it’s just extremely inefficient, and will actually slow down your site by adding an additional request to each and every ping to your origin server.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!