WPLift is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.
How to Use Cloudflare Full-Page Caching With WordPress (for Free!)
Interested in a powerful way to speed up your site’s global load times? Using Cloudflare full-page caching for WordPress lets you serve your entire WordPress site from Cloudflare’s huge global network, which offers impressively consistent (and fast) global load times.
However, if you want to avoid breaking your WordPress site, you’ll need to properly configure full-page caching, which is the topic of this post.
I’ll show you two ways to safely enable full-page caching on Cloudflare:
- Using Cloudflare’s new Automatic Platform Optimization service, which costs $5 per month.
- Using a 100% free WordPress plugin with the free Cloudflare plan. This adds a little complexity, but lets you avoid the $5 per month fee.
Ready to get started? Let’s dig in…
Why Use Cloudflare Full-Page Caching on WordPress?
Put simply, using Cloudflare full-page caching will make your site load blazing fast no matter where your visitors are.
Check out this chart from Wordfence’s Fast or Slow tool, which tests from 18 different locations all across the globe:
You can see that, with a few exceptions (e.g. Bahrain), the load times are pretty uniform at around 500 ms no matter if it’s the USA, Hong Kong, Australia, Brazil, France, or anywhere else.
That’s awesome, and that’s the big benefit of fully caching your site with Cloudflare.
Note, this chart is from the actual test site that I’m using for this tutorial.
Article Continues Below
The Problem With Cloudflare Full-Page Caching and WordPress
Ok, so Cloudflare does include a setting to Cache Everything on the free plan, which might have you thinking that you can just set your WordPress site up with Cloudflare, enable Cache Everything, and call it a day.
Well, you certainly can do that, and it would lead Cloudflare to cache your entire WordPress site…
However, doing it this way is going to cause all kinds of problems because Cloudflare won’t be able to detect sessions for logged-in users, exclude critical pages, and more.
Basically, your site’s gonna break.
For example, let’s say you’re logged in to your WordPress admin account and you visit a blog post with comments. Then, Cloudflare sucks that page into its cache.
Well, guess what, when an anonymous visitor goes to that page, it’s still going to look like they’re logged in as the admin (even though they won’t be able to actually access your admin dashboard).
Or, if you have a WordPress membership site with restricted content, your logged-in members won’t be able to see the restricted content because they’ll be served the cached version that anonymous visitors see.
Honestly, I’m not developer’y enough to know exactly what’s going wrong. I just know that it doesn’t work because it’s got something to do with cookies and user sessions and stuff like that.
If you wanted to fix this, your only option used to be to pay for the expensive $200 per month Cloudflare Business plan. Now, you have two options:
- Use Cloudflare’s new Automatic Platform Optimization service, which is much more affordable at $5 per month.
- Use the free plugin in the tutorial below, which is 100% free.
Keep reading and I’ll show you how to set everything up…
But First – Add Your Site to Cloudflare
Before you can use either of these methods, you first need to add your site to Cloudflare, which involves adding your site via the Cloudflare interface and changing your nameservers to point towards the nameservers that Cloudflare gives you.
If you’re not sure how to do this, check out our full guide on how to set up Cloudflare for WordPress.
Method 1. Use Cloudflare’s Automatic Platform Optimization
When I first started writing this tutorial, your only option was to use the free plugin that I’ll detail in the second method. Then, in the middle of my first draft, Cloudflare decided to announce its new Automatic Platform Optimization service, which basically solves the problem for a much more affordable $5 per month (vs the previous method, which required the $200 per month Business plan). Or, it’s also now included for free with any paid Cloudflare plan.
If you’re willing to pay the $5 per month, this is a great way to get started because setting it up is super simple.
Once you’ve added your site to Cloudflare, install the free Cloudflare companion plugin on your site and activate it. You’ll need to enter your Cloudflare account’s email address as well as your API key/token, which you can find on this page. Use the WordPress template when creating your API token, or you can just use your global API key.
Then, in the plugin’s settings, look for the Automatic Platform Optimization toggle and turn it on. If you’re on the free plan, you’ll first see a prompt to Purchase it before you can enable it:
And that’s it! It’s not free, but it’s super simple.
Method 2. How to Set Up Cloudflare Full-Page Caching on WordPress for Free
To use Cloudflare’s Cache Everything rule on WordPress without breaking your site and while staying on the free Cloudflare plan, you can use the awesome free WP Cloudflare Super Page Cache plugin.
The plugin works by using HTTP response headers to control caching behavior on Cloudflare. Even on the Cloudflare free plan, Cloudflare will still respect the headers.
I wrote a post for WP Rocket on cache-control HTTP headers if you want to know what all that stuff means. But basically, all you need to know is that this plugin lets you use Cache Everything on the free Cloudflare plan without breaking your WordPress site. It’s even compatible with eCommerce stores powered by WooCommerce or Easy Digital Downloads.
To get started, install, and activate the plugin. Then, here’s how to set it up.
1. Create a Cloudflare Token
To connect to your site, WP Cloudflare Super Page Cache gives you two options:
- You can use your global Cloudflare API key. This is the simplest option, but I personally don’t want to have the global key floating around because I have a lot of sites in my Cloudflare account.
- You can create a dedicated API token for just this site. While it adds a few steps, I’m going to recommend this method because it’s the most secure.
To create a dedicated Cloudflare token, go to this page and click the Create Token button:
On the next screen, click Get started next to Create Custom Token:
Now, you’ll need to enter a name and then configure it as follows:
- Account – Account Settings – Read
- Account – Worker Scripts – Edit
- Zone – Cache Purge – Purge
- Zone – Page Rules – Edit
- Zone – Zone Settings – Edit
- Zone – Zone – Edit
- Zone – Worker Routes – Edit
Choose your Cloudflare account
Choose your WordPress site.
Then, click Continue to the summary:
On the summary page, click Create Token. Now, you should see your token. Keep this handy because you’ll need it in the next step.
2. Add API Token to Plugin’s Settings
Next, go to Settings → WP Cloudflare Super Page Cache in your WordPress dashboard and configure things as follows:
- Authentication Mode – API Token
- Cloudflare API Token – paste in the API token that you generated in the previous step.
- Cloudflare Domain Name – your site’s domain name exactly as it appears in your Cloudflare account.
Then, click Update Settings:
3. Enable Page Caching
Once you add your API token, you should see a prompt at the top of the page to Enable Page Caching. Click that and you should be set to jet:
To make sure that everything is working, click the Test Cache button:
You can also use this area to quickly purge your site’s cache.
4. Configure Page Caching Behavior (Optional)
The plugin should work with its default settings. However, you have lots of options to tweak things if you want to. This might also be necessary for some situations to get the behavior that you want.
For example, by default, the plugin will add a query parameter to the end of URLs for logged-in users that looks like this: https://thebesttest.website/?swcfpc=1
This query parameter acts as a cache buster for logged-in visitors. However, if you don’t like that it displays, you can enable Worker Mode in the plugin’s Cache settings:
There are also lots of other well-documented settings here, so I recommend that you explore them all.
And that’s it! Your site is now benefiting from full-page caching on Cloudflare for free.
Start Using Cloudflare Full-Page Caching for WordPress Today
Personally, I don’t like using the Cloudflare CDN for partial content, but it’s a whole different ball game when you’re using full-page caching with Cloudflare.
However, the downside of full-page caching by default is that it can break the dynamic parts of your WordPress site.
The methods in this post change that, letting you benefit from speedy global load times while still serving dynamic content.
If you’re willing to pay, the simplest option is to just use Cloudflare’s $5 per month Automatic Platform Optimization service for WordPress.
Or, if you’re more of the DIY type, you can set it up for free with the WP Cloudflare Super Page Cache plugin.
Still have any questions about using Cloudflare full-page caching on WordPress? Ask in the comments!
One thought on “How to Use Cloudflare Full-Page Caching With WordPress (for Free!)”
Really cool options! I’ll check which one can fit better into my latest project and deploy it. Hope it will boost even more the speed, than serving just partial cached resources (creating a CDN with Backblaze B2 and Cloudflare for free is also a gorgeus thing that I discovered some time ago)
Thank you for the article!
Comments are closed.