Looking for a fast, scalable, free page cache solution without plugin that will speed up your WordPress website? This is how I use Cloudflare for caching dynamic pages.
It is a simple, free and fastest caching solution. After initial setup caching will work automatically without using any plugin.
Pluginless solution is a way to go if:
- You want to leverage the power of caching without using your own server resources.
- Annoyed by regular (weekly) plugin updates that have the potential risk of breaking some site functionality.
- Don’t like huge plugins with lots of unneeded features that regularly wastes your server resources.
Then this simple page cache solution on free Cloudflare CDN is for you.
Watch a video tutorial on Youtube.
Playlist to watch more WordPress speed optimization tutorials.
Table of Contents
How to set up WordPress page cache on CDN?
Step 1: Login to Cloudflare and select the website you want to use page cache.
Step 2: Navigate to “Cache” → “Cache Rules” page from the side menu.
Step 3: Click on the “Create Rule” button.
Step 4: Give a descriptive rule name like “Static html” or “wp page cache” for example.
Step 5: For “If incoming requests match…” field select “Custom filter expression”.
Step 6: Add following rules:
Cookie
→does not contain
→wordpress_login_in_
Cookie
→does not contain
→wp-postpass_
Cookie
→does not contain
→comment_author_
- Additional optional cookie rules if your WordPress uses WooCommerce plugin:
Cookie
→does not contain
→woocommerce_items_in_cart_
Cookie
→does not contain
→wp_woocommerce_session_
URI Path
→does not contain
→/wp-admin
URI Path
→does not contain
→/wp-login
Additionally define any URI Path and Cookie rules that should not be cached. Hostname
→ Equals
→ yourdomain.com
rule can be used to match domain if you are using different subdomains for your website.
Easy way of adding these custom rules can be done using the “Edit Expression” link.
(not http.cookie contains "wordpress_logged_in_" and not http.cookie contains "wp-postpass_" and not http.cookie contains "comment_author_" and not http.cookie contains "woocommerce_items_in_cart_" and not http.cookie contains "wp_woocommerce_session_" and not http.request.uri.path contains "/wp-admin" and not http.request.uri.path contains "/wp-login")
Paste following expression to add page rule for WordPress website. It is helpful when you need to add page cache to multiple WordPress websites.
Step 7: For “Cache Eligibility” field select “Eligible for cache” option
Step 8: For “Edge TTL” select “Ignore cache-control header and use this TTL” option. Then select TTL value as “1 day”.
Step 9: Scroll down and click the “Save” button.
After defining these page cache rules your website will be cached and served from Cloudflare CDN servers.
Rules defined here use cookies to detect if a user logged in or needs to view not cached pages. Page rules exclude admin and login pages from being cached.
All other pages will be cached and served from CDN.
Top 3 benefits to cache WordPress pages on CDN
CDN has many speed and security benefits for websites. Here are the most important performance benefits of using CDN level caching for WordPress websites.
1. Scaling the website to serve millions of page views
There are 2 important performance metrics when looking at caching locations.
- Page serving speed, time taken to serve a page.
- Page serving capacity, number of pages that can be served per second.
We can see that CDN level cache is fast because content is stored on CDN and can be served as static content without reaching to your origin server.
Also page serving capacity is high on CDN because they have many thousand servers in different data centers around the world that can send your page to many users at the same time without problem.
2. Faster page loading time from any location around the globe
Cloudflare has many servers in different countries. Your cached WordPress pages will be served from the closest location to the user.
Content is physically located in multiple locations and served from closest location to the user.
As you can see from the screenshot page cache was “HIT
” meaning served from cache. TTFB time to load a page was on average around 100ms
. Which is very fast page load time that matches enterprise level servers for free.
Above screenshot, that shows cache hit status and cache serving location, taken from speedvitals website.
3. Free up origin server for performing more operations
Beauty of caching is saving once and serving many times. My blog has around 100 pages that are generated once and served thousand times every day. This helps to free up my origin server resources.
Your origin web server will work on idle most of the time.
This means any shared hosting can handle WordPress websites without hitting processor and memory limitations.
FAQ
How to cache if you are using subdomain?
Add an additional caching rule to match Host
→ Equals
→ sub.yourdomain.com
. Defining a host is helpful if you have different subdomains for different purposes.
For example when your main WordPress website is on yourdomain.com
(you want to cache) and some other CMS on sub.yourdomain.com
(you do not want to cache). Apply caching to the main website only. Define host equals to “yourdomain.com
“. Content from sub.yourdomain.com
will not be cached.
You need to explicitly define which domain should be cached because cache rules in Cloudflare apply to all domains and subdomains automatically.
How to cache if your WordPress website is in a subfolder?
When your WordPress website is served from the subfolder “yoursubfolder” then you should add URI Path
→ contains
→ /yoursubfolder
rule to Cloudflare cache.
How to add page cache on Cloudflare for multiple websites?
Easiest way to apply the same cache rules to multiple websites is by using a previously defined expression.
Copy and apply the same expression to every website using the “Edit expression” link inside cache rule. You need to go to each website individually and paste the same expression.
This will speed up setting up page cache for multiple websites powered by WordPress. These rules will work only with WordPress because it uses WordPress related URI path and cookie values.
How to validate if Cloudflare page cache for WordPress is working?
Check Response Headers for Cf-Cache-Status: HIT
value following these steps:
- Open your website in the incognito Chrome browser and click
F12
(or right mouse click on the page and select “Inspect” from submenu). Make sure you are not logged in. - Navigate to the “Network” tab.
- Reload page with
F5
. - Click on the “Doc” tab and click on the line corresponding to the document url.
- In “Response Headers” you should see the
Cf-Cache-Status: HIT
record.
How to clear Cloudflare Cache cache manually?
To clear cache immediately:
- Navigate to the “Caching” → “Configuration” page on Cloudflare when your website property is selected.
- On the opened page click the “Purge Everything” button and confirm your choice.
- All cache will be cleared within 30 seconds.
Normally you do not need to clear cache manually when cache TTL time is set to low value like 1 day
. Because cache will expire automatically after one day and new page will be served from Cloudflare.
Why is this method better than using WordPress plugin for caching on CDN?
Using Cloudflare page cache for WordPress without a plugin is better because it does not need a separate plugin installed in WordPress.
Plugin can be handy if you do not want to manually create cache rules. There is a plugin called “Super page cache for Cloudflare” where you enter cloudflare API and it configures page cache rules for your website automatically.
Reasons for not using a plugin to manage Cloudflare page cache for WordPress.
- Plugins has many settings that can take more time to set up and can be confusing. Settings like fallback page cache, browser cache, cache purging on content update etc.
- Plugins update regularly (almost every week) and have the risk of breaking some settings with each update. Broken features will be fixed a couple weeks later.
- Plugins tend to be monetized and stay profitable in order to be able to provide constant support. This forces them to add more features for staying competitive. As a result plugins are bloated with useless features, upsells, adverts etc. More plugins and plugins with more features and code in return slows down your WordPress website.
In the past I was using the Super page cache for Cloudflare plugin because of its ease of use. But in 2024 they moved away from being a niche plugin for just cloudflare cache and moved towards being a general caching plugin for WordPress.
This move made it difficult to use just page cache for cloudflare features. That is one of the reasons to set up page cache directly on cloudflare and reduce the number of plugins in WordPress website.
Conclusion
Page cache on CDN is a nice performance booster for WordPress website. It is completely free, easy to set up and an efficient way of speeding up a WordPress website.
Similar caching rules can be applied to other CMS or custom built websites as well. All you need to know is cookie and URI values for serving fresh (not cached) content. I use this method on classifieds, gaming and ecommerce websites as well.
What is next:
- In case Cloudflare is not an option for you then using the simplest page cache plugin will be sufficient for getting PageSpeed score 100.
- As part of WordPress optimization I regularly tend to reduce the number of plugins. Learn ways to reduce plugins with examples.
- Use a fast native share button without plugin.
- Download a free checklist that I use to get a 90+ mobile PageSpeed score for WordPress websites.