Free website audit. We review your site and show you what is costing you customers.Get yours

How to Reduce TTFB With Cloudflare Edge Cache Rules

Cut WordPress TTFB by caching your pages at the Cloudflare edge. Two free Cache Rules, the exact expressions to paste, and how to check it works.

hamzahamza6 min read

To reduce TTFB with Cloudflare, create two Cache Rules: one that makes your WordPress pages eligible for cache at the edge, and one that bypasses the cache for logged in users, the admin area and carts. Then install the Cloudflare WordPress plugin so the cache clears when you update a post. Visitors then get your pages from a Cloudflare server near them, instead of waiting for WordPress to build each page.

By default, Cloudflare caches images, CSS and JavaScript, but not the HTML of your pages. That HTML is what decides your TTFB. This guide fixes that on the free plan.

What edge caching does to TTFB

TTFB (time to first byte) is how long the browser waits before the first byte of your page arrives. Google’s guidance treats 0.8 seconds or less as good. On WordPress, most of that wait is the server running PHP and database queries to build the page.

We tested this on our own product site, berqwp.com, which uses Cloudflare edge caching. Three requests came from the Cloudflare cache, and three skipped it with a random query string so they went to the server.

Terminal output showing TTFB of about 0.09 seconds on Cloudflare cache hits and 0.83 to 1.06 seconds when the cache is bypassed
Requestcf-cache-statusTTFB
Served from Cloudflare cacheHIT0.09 to 0.10 seconds
Sent to the serverBYPASS0.83 to 1.06 seconds

Same page, same connection, measured on 29 November 2026. Serving it from the edge cut the wait by about 90%. Your numbers will differ with your host and location, but the gap is usually large. If you are choosing a host, our guide to what a small business website costs covers typical hosting prices.

Before you start

  • Your domain uses Cloudflare, and the DNS records for your site show the orange cloud (Proxied). Cache Rules only work on proxied records.
  • Your site is not personalised for logged out visitors. If every visitor sees different content, such as a membership site, test carefully first.
  • You know your WooCommerce cart, checkout and account page URLs, if you run a store.

Cache Rules are available on every Cloudflare plan. The free plan allows 10 rules, and this setup needs only 2.

Rule 1: Cache WordPress pages at the edge

  1. In the Cloudflare dashboard, open your domain and go to Caching, then Cache Rules.
  2. Select Create rule and name it “Cache WordPress pages”.
  3. Under When incoming requests match, choose Custom filter expression, select Edit expression and paste the expression below. Replace example.com with your domain.
  4. Under Cache eligibility, select Eligible for cache.
  5. Under Edge TTL, select Ignore cache-control header and use this TTL and choose 1 day. You can raise it once automatic purging works.
  6. Under Browser TTL, select Respect origin. This keeps browsers from holding on to old copies of your pages.
  7. Select Deploy.
(http.host eq "example.com")

If your site also loads on www, use (http.host in {"example.com" "www.example.com"}) instead.

Rule 2: Bypass the cache where it would break things

Logged in users, the admin area, previews, search results and carts must always come fresh from WordPress. Create a second rule named “Bypass WordPress dynamic pages”, paste this expression, and set Cache eligibility to Bypass cache.

(http.request.uri.path contains "/wp-admin")
or (http.request.uri.path eq "/wp-login.php")
or (http.request.uri.path contains "/wp-json/")
or (http.request.uri.path eq "/xmlrpc.php")
or (http.cookie contains "wordpress_logged_in")
or (http.cookie contains "wp-postpass")
or (http.cookie contains "comment_author")
or (http.cookie contains "woocommerce_items_in_cart")
or (http.cookie contains "wp_woocommerce_session")
or (http.request.uri.path contains "/cart")
or (http.request.uri.path contains "/checkout")
or (http.request.uri.path contains "/my-account")
or (any(http.request.uri.args.names[*] == "preview"))
or (any(http.request.uri.args.names[*] == "s"))

If you do not run WooCommerce, you can leave out the WooCommerce cookie and cart lines. If your store uses different page addresses, change the cart, checkout and account paths to match.

Put the bypass rule last

Cloudflare runs every matching Cache Rule in order. When two rules set the same thing, the last matching rule wins. So the bypass rule must sit below the caching rule. If it sits above, the caching rule overrides it, and logged in users or shoppers could see cached pages.

Check the order on the Cache Rules page and drag “Bypass WordPress dynamic pages” to the bottom if needed.

Clear the cache when you update content

Cloudflare plugin page on WordPress.org

With edge caching on, visitors see the cached copy until it expires. To show updates straight away, install the official Cloudflare plugin from WordPress.org, connect it with an API token, and turn on Auto Purge Content On Update. It clears the cached copy when you publish, edit or delete a post. This works on the free plan and does not need Cloudflare’s paid APO feature.

Once purging works, you can raise the Edge TTL in Rule 1 to a week or a month. Pages then stay cached longer and fewer requests reach your server.

Turn on Smart Tiered Cache

Go to Caching, then Tiered Cache, and enable Smart Tiered Caching Topology (how Tiered Cache works). Cloudflare data centres then ask each other for a cached copy before asking your server. This raises the hit rate for visitors in countries far from your host, and it is free.

Check that it works

  1. Open your homepage in a private browser window, so you are logged out.
  2. Open the developer tools, go to the Network tab and reload the page twice.
  3. Select the first request, the page itself, and look for the cf-cache-status response header.
cf-cache-statusWhat it means
HITServed from the Cloudflare cache. This is the goal.
MISSNot in the cache yet. Reload once more and it should become HIT.
BYPASSA bypass rule matched. Expected when logged in or on cart pages.
DYNAMICThe page is not eligible for cache. Check that Rule 1 is deployed and matches your hostname.

Then log in to WordPress and load the same page. It should show BYPASS. If it shows HIT while you are logged in, move the bypass rule to the bottom.

Common problems

The page never becomes HIT. A plugin may be setting a cookie on every page, which can stop the response from being cached. Look for a set-cookie header on the page response and find the plugin that adds it.

Forms or nonces stop working. Some forms include a security token that expires. A page cached for too long can serve an old token. Lower the Edge TTL, or exclude the page with the form in Rule 2.

TTFB is still high on the first visit. The first request to each data centre is a MISS and goes to your server. Smart Tiered Cache helps, and a page cache plugin on the server keeps those first requests quick too.

Edge caching and a page cache plugin work together

Cloudflare caches pages near your visitors. A page cache plugin on your server, one of the WordPress plugins that help increase traffic, makes every cache miss fast and handles what Cloudflare cannot, like image compression and unused CSS. Use both. If you would rather not write rules by hand, BerqWP, the speed plugin our team builds, can connect to your Cloudflare account, create the cache rule for you and clear the cached copy of a page when it changes.

hamza
Written by hamza

Keep reading

All articles →

Ready to turn more visitors into customers?

Start a project →