Skip to content

WordPress Page Cache Without Plugin on Free Cloudflare CDN

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.

How to set up WordPress page cache on CDN?

Step 1: Login to Cloudflare and select the website you want to use page cache.

Select Caching → Cache rules from Cloudflare side menu

Step 2: Navigate to “Cache” → “Cache Rules” page from the side menu.

Create new cache rule in Cloudflare.

Step 3: Click on the “Create Rule” button.

Name cloudflare cache rule for ease of use

Step 4: Give a descriptive rule name like “Static html” or “wp page cache” for example.

Select Custom Expression option for caching in Cloudflare

Step 5: For “If incoming requests match…” field select “Custom filter expression”.

Add custom rules to define pages that should be cached and served from cache on Cloudflare.

Step 6: Add following rules:

  • Cookiedoes not containwordpress_login_in_
  • Cookiedoes not containwp-postpass_
  • Cookiedoes not containcomment_author_
  • Additional optional cookie rules if your WordPress uses WooCommerce plugin:
    • Cookiedoes not containwoocommerce_items_in_cart_
    • Cookiedoes not containwp_woocommerce_session_
  • URI Pathdoes not contain/wp-admin
  • URI Pathdoes not contain/wp-login

Additionally define any URI Path and Cookie rules that should not be cached. HostnameEqualsyourdomain.com rule can be used to match domain if you are using different subdomains for your website.

Cache rules in easy to duplicate expression format. Useful for migrating same rules to other WordPress websites.

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.

Select Eligible for cache option for currently defined rules.

Step 7: For “Cache Eligibility” field select “Eligible for cache” option

Define caching period as 1 day. This is optimal time for most WordPress websites.

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

WordPress average page cache performance for different caching levels. Table shows initial server response time and page serving capacity per second for each level.

There are 2 important performance metrics when looking at caching locations.

  1. Page serving speed, time taken to serve a page.
  2. 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

TTFB table view from different locations with cache HIT status report in SpeedVitals.

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

Report shows that 97 percent of content for my website served from free cloudflare CDN cache

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 HostEqualssub.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 Pathcontains/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.

Cache rules in easy to duplicate expression format. Useful for migrating same rules to other WordPress websites.

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:

Validate that Cloudflare page cache is working by checking response headers for (Cf-Cache-Status: HIT) record.

  1. 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.
  2. Navigate to the “Network” tab.
  3. Reload page with F5.
  4. Click on the “Doc” tab and click on the line corresponding to the document url.
  5. In “Response Headers” you should see the Cf-Cache-Status: HIT record.

How to clear Cloudflare Cache cache manually?

Purge cache from Cloudflare dashboard when needed.

To clear cache immediately:

  1. Navigate to the “Caching” → “Configuration” page on Cloudflare when your website property is selected.
  2. On the opened page click the “Purge Everything” button and confirm your choice.
  3. 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.

  1. 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.
  2. 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.
  3. 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:

Leave a Reply

Your email address will not be published. Required fields are marked *