Skip to content
Blog

Do you need a CDN for WordPress? How Cloudflare works

Do you need a CDN for WordPress? What a CDN does, how Cloudflare caching works, when it helps, and how to read the cache headers to check it.

The WP Waterfall team · Guides

Most WordPress sites with visitors in more than one region benefit from a CDN, and a site with a local audience on a fast host may not. A CDN, or content delivery network, keeps copies of your files on servers close to your visitors, so the files travel a shorter way and your own server answers fewer requests. Cloudflare is the most common one. This guide explains how its caching works and how to check that it is doing its job.

Key takeaways

  • A CDN serves static files from a nearby location. With page caching turned on, it can serve whole pages too.
  • By default Cloudflare caches static files by their extension, such as images, CSS, and JavaScript, and does not cache HTML pages.
  • You can read the answer in one header: cf-cache-status says HIT when the CDN served the file.

What does a CDN do for WordPress?

Without a CDN, every visitor downloads every file from your server, wherever they are. A visitor in Sydney waits for a round trip to a server in Virginia for each image, stylesheet, and script. A CDN keeps copies at many locations. The visitor in Sydney gets the copy from Sydney.

That gives you three things:

  • Speed. Files travel a shorter distance, and the CDN uses fast connections and compression.
  • Less load on your server. The CDN answers most requests for files, so your server handles fewer.
  • A buffer. A traffic spike lands on the CDN first, and a CDN also filters some bad traffic before it reaches you.

How does Cloudflare caching work?

When a request reaches a Cloudflare location, it looks in its cache for the file.

  1. If it has a fresh copy, it answers at once. This is a HIT.
  2. If not, it asks your server, stores the answer, and sends it on. This is a MISS.
  3. The next visitor to that location gets the stored copy.

A copy stays fresh for the time your server allows in the Cache-Control header, or for the time you set in a Cloudflare rule. When it expires, Cloudflare asks your server again. You can also clear a file on purpose, which is called a purge.

Two defaults matter for WordPress:

  • Cloudflare caches static files by extension: images, CSS, JavaScript, fonts, and similar. It does not cache HTML by default, because an HTML page can differ for each visitor.
  • To cache whole pages, a rule has to say so, and the rule has to skip logged in users, carts, checkouts, and previews. If it does not, one person's private page can be served to another.

Each location keeps its own cache. That is why the first visitor in a new region may see a MISS even when the file is cached somewhere else.

How do you check that the CDN works?

Ask for a file and read the headers:

curl -sI https://example.com/wp-content/themes/mytheme/style.css | grep -iE '^(cf-cache-status|age|cache-control):'

Run it twice. The first answer may say MISS or EXPIRED, and the second should say HIT. These are the values you will see:

cf-cache-status Meaning
HIT Served from the CDN's cache
MISS Not in the cache, fetched from your server and stored
EXPIRED The copy was too old, so it was fetched again
STALE or REVALIDATED An old copy was served while a new one was checked
DYNAMIC Cloudflare did not consider the file cacheable, so it went to your server
BYPASS A rule told Cloudflare not to cache it

The age header says how many seconds the copy has been in the cache. If you see DYNAMIC for an image or a stylesheet, something is telling Cloudflare not to cache it, usually a Cache-Control header such as private or no-store, or a rule that says to bypass the cache.

Do you need a CDN?

You probably do when:

  • Your visitors are spread across countries or continents.
  • Your pages carry many images, video, or large scripts.
  • Your traffic comes in spikes, such as a launch or a viral post.
  • Your server is small and the load is mostly files.

You can probably wait when your audience is in one city near the server, your site is small and mostly text, and the host already serves it well. In that case a page cache on the server is the bigger win. Read What a page cache can and cannot do first.

What are the common mistakes?

  • Caching private pages. A rule that caches HTML must skip anyone with a login or cart cookie.
  • Forgetting to purge. If you replace a file and keep its name, clear it at the CDN, or visitors keep the old file until it expires.
  • Stacking cache layers. A page cache plugin, the host's cache, and the CDN each keep a copy. Know which one holds the stale page before you clear all three.
  • Caching with the wrong query strings. Tracking parameters such as utm_source can make every URL look new. A good rule ignores them.
  • Mixed content. A page served over HTTPS that loads an image over HTTP shows a warning. Fix the address in the database with a search and replace.

How does it work on WP Waterfall?

Every WP Waterfall site gets Cloudflare edge caching with nothing to buy and nothing to turn on. Each Cloudflare location your visitors reach keeps copies of your HTML pages and your static files. A Smart Tiered Cache asks an upper location before it asks your server for a static file, and Argo Smart Routing takes the fastest path for requests that must reach your server, such as logged in visitors and carts. Brotli makes files smaller.

The cache skips what it should: a logged in visitor, a cart, a POST, and a response that sets a cookie. The edge keeps a page for an hour by default, and you can set that from 30 minutes to 30 days. You can purge one URL, a path, or a group of pages, and publishing a post clears the pages it touches. Every page carries an x-wpwaterfall-cache header with HIT, MISS, BYPASS, STALE, or EXPIRED, next to Cloudflare's own cf-cache-status. The details, including rules and exclusions, are in Edge cache and CDN. An AI assistant connected through the WordPress MCP server can clear the CDN with the purge_cdn tool.

Read next

Try what you just read about.

See it in your own dashboard.