CDN Caching: How It Works and How to Set It Up Right

CDN caching means a network of servers keeps copies of your site’s files close to your visitors, so most requests never travel to your origin server at all. Done right, pages load faster, your host does less work, and your bandwidth bill shrinks. Done wrong, visitors see stale pages or, worse, someone else’s private data. This guide covers what a CDN actually stores, how headers and time-to-live settings control it, how to refresh content on demand, and how to tell whether your cache is working. We test hosting for a living, and cache behavior is one of the first things our benchmarks expose.

SycamoreNet
Choose Hosting That Supports Site Speed
Compare managed WordPress hosting options as you consider how hosting and caching choices affect site speed and origin workload.

Best WordPress Hosting

Key Takeaways

  • A CDN checks its own cache first. A hit is served from the edge; a miss goes to your origin, and the response may be stored for the next visitor.
  • Your Cache-Control headers, not the CDN dashboard alone, decide what is cached and for how long. Public files can be cached widely. Private or user-specific responses must never be.
  • A higher hit ratio cuts origin load sharply: going from 90% to 95% halves the number of requests that reach your server.
  • Use long cache lifetimes plus purging for content that changes, instead of very short lifetimes that keep emptying the cache.
  • Caching is only one thing a CDN does. A host with edge caching built in saves you from wiring it up yourself.

Table of Contents

What CDN caching is and how a request flows

A content delivery network (CDN) is a set of servers spread across many locations. When a visitor loads your site, the request goes to the nearest of those servers, called an edge or point of presence, instead of to your single origin server, which is the machine that actually hosts your site.

The flow is simple:

  1. The visitor asks for a file, say your logo or a blog post.
  2. The edge server checks whether it holds a fresh copy. According to Google’s web.dev guide to CDNs, a hit is returned directly, while a miss is fetched from the origin and may be stored for later requests.
  3. The next visitor near that edge gets the stored copy.

Two details trip people up. First, cache filling is usually reactive: the CDN does not copy your whole site in advance, it builds its cache as objects are requested. So the first visitor in a region often gets a slower response than the hundredth. Second, one edge location does not automatically share its cache with the others. A page can be warm in Frankfurt and cold in Dallas.

Get Big Discounts for Internet, Phone, Mobile, and WIFI.
Up to 50% off
Toll-Free Number 1-855-202-7237
(Xfinity, Spectrum, COX, Verizon, AT&T, T-Mobile, etc.)

This is why a single speed test can mislead you. We run cold-cache and warm-cache tests separately in our hosting benchmarks, because the gap between the two tells you how much work your origin does when the cache cannot help.

Why it speeds up your site and lowers costs

There are three gains, and they stack.

Latency. Data has a physical distance to travel. Serving a file from a server in the visitor’s region instead of one across an ocean removes round trips. For a US store with customers in Europe or Asia, this is often the biggest single improvement to time to first byte (TTFB), the time before the browser receives the first byte of a response.

Origin load. Every hit is a request your server never handles. That means fewer PHP processes, fewer database queries and more headroom when a post gets a traffic spike. On a shared or entry-level plan, that headroom is often the difference between a fast page and a timeout.

Bandwidth. Fewer requests reaching the origin means less outbound data from your host. Imperva’s CDN guide says that serving from CDN cache proxies can cut bandwidth costs by 40% to 80% for most sites, depending on how much of the content is cacheable. That range is the point: a mostly static blog sits near the top, a logged-in membership site near the bottom.

The hit ratio math

The cache hit ratio is the share of requests answered from cache. The reason a few points matter so much is that misses are what hurt. At a 90% hit ratio, 10 of every 100 requests reach your origin. At 95%, only 5 do. You improved the ratio by five points and cut origin traffic in half.

Origin requests halve as hit ratio rises

One caveat: the ratio counts requests, not bytes. A site where a few huge video or download files miss the cache can look healthy by request count while still pushing a lot of data from the origin. Check both numbers if your CDN dashboard shows them.

What a CDN can cache, and what it must not

The safe rule is to cache what is the same for everyone. Google’s web.dev guidance identifies public resources as suitable for shared caching and says user-specific resources should not be cached by a CDN.

Good candidates:

  • Images, fonts, video and downloadable files
  • CSS and JavaScript files, especially versioned ones (a filename or query string that changes when the file changes)
  • Public HTML pages such as blog posts, landing pages and category pages

Never cache at the shared edge:

  • Cart, checkout and account pages
  • Anything that contains a logged-in user’s name, orders or personal details
  • Responses to requests that carry a login cookie, unless your setup varies the cache explicitly

If you run WooCommerce, this is the line that matters most. A product page can be cached. The cart and checkout cannot. A misconfigured rule that caches a cart page can show one shopper another shopper’s basket. That is a privacy failure, not a speed problem.

Also, a CDN does not store everything everywhere. Varnish’s documentation notes that it is a myth that a CDN has all objects cached globally: storage is limited, so networks are selective and may skip rarely requested files until they are asked for again. If an old image is slow once in a while, that is why.

How headers, cache keys and TTLs decide what is served

Three controls do most of the work.

Cache-Control headers

Your origin attaches headers to each response telling every cache what it may do. The ones you will meet most:

  • max-age=N sets how many seconds the response counts as fresh.
  • s-maxage=N does the same for shared caches such as CDNs, and overrides max-age there. Per Cloudflare’s cache-control documentation, browsers ignore s-maxage, so you can give the CDN a long lifetime and browsers a shorter one.
  • private prohibits storage by shared caches, so the CDN will not keep it. no-store prohibits storage by any cache, including the visitor’s browser.
  • public marks a response as safe for shared caches.

Two newer directives are worth knowing. stale-while-revalidate lets a cache serve a slightly stale copy while it fetches a fresh one in the background, so visitors never wait on a revalidation. stale-if-error lets it serve the last good copy when the origin is down. Both are supported by most CDNs, and they are the reason a well-tuned cache can stay fast even when the origin stumbles.

CDNs differ on which header wins when several are present. Some give priority to their own header, then s-maxage, then max-age, then Expires. Read your provider’s order before you debug, because the same response can behave differently on two networks.

Cache keys

The cache key is the label the CDN uses to look up a stored response, usually built from the URL and sometimes from headers or cookies. It carries a trade-off. A key that is too broad can serve the wrong response to the wrong person. A key that is too narrow fragments the cache: if every tracking parameter such as ?utm_source= creates a new key, the same page is stored dozens of times and your hit ratio collapses. Ignoring marketing parameters in the key is one of the cheapest hit ratio wins on a content site.

Time to live (TTL)

TTL is how long an object stays fresh. Pick it by how often the content changes. Google Cloud’s best practices give two examples: five seconds for near-real-time sports scores and one hour for weather updates. Your site probably sits at the long end for most files.

A workable starting point:

Content Typical lifetime Why
Versioned CSS and JS One year The filename changes when the file does
Images and fonts Weeks to months Rarely edited after upload
Blog posts and landing pages Hours to days, with purge on update Change occasionally, and you control when
Home page with a news feed Minutes Changes often
Cart, checkout, account Not cached Personal to each visitor

These are our working defaults, not a standard. Adjust them to how often your own pages change.

Purging: updating content without waiting for expiry

A long TTL is great until you fix a typo and the old version stays live for a day. You have two options: wait, or purge. Purging explicitly removes an object before it expires. That is different from eviction, which is the CDN removing less-useful objects on its own as storage fills.

The better pattern is not to shorten your TTLs to stay current. Fastly’s documentation recommends pairing a longer cache duration with purging when content changes, rather than very short lifetimes, because that improves both hit ratio and responsiveness. Short TTLs make the CDN keep returning to your origin even when nothing has changed.

Practical rules:

  • Purge by URL when you edit one post. Purge everything only after a site-wide change such as a theme update, since a full purge sends a burst of misses to your origin at once.
  • Automate it. Most WordPress cache plugins and managed hosts purge the affected URLs when you hit Update. Confirm yours does, including the home page and category pages that list the post.
  • Version your assets. If a stylesheet filename changes with each release, you never need to purge it.
  • Purge the browser too. A CDN purge does not clear a visitor’s browser copy. If you set a long max-age, some visitors keep the old file until it expires, which is another reason to give browsers shorter lifetimes than the CDN.

How to check that your CDN cache is actually working

Do not trust the dashboard alone. A quick check takes a minute.

  1. Open your browser’s developer tools, go to the Network tab and reload a page.
  2. Click the main document and read the response headers. Most CDNs add a header showing hit or miss status and the age of the cached copy.
  3. Reload. The first load of a page may show a miss, the second should show a hit with an age above zero.
  4. Test an image and a stylesheet as well, not only the HTML. These often behave differently.
  5. Test a logged-out and a logged-in session. The logged-in view of a personalized page should not be served from a shared cache.

If you see constant misses, the usual causes are, per Fastly’s best practices, restrictive cache-control headers, fragmented cache keys, short TTLs and unexpected traffic patterns. Work through them in that order: look at your headers first, then at query strings and cookies in the key, then at your TTLs.

If you see stale content, check the TTL and whether your purge ran. If you see errors or odd pages for some visitors only, suspect a cache key that is too broad or a rule caching something personal.

Is a CDN just a cache?

No. Caching is the best-known feature, but modern CDNs also terminate TLS (the encryption layer), absorb DDoS traffic, run web application firewalls and bot filters, and can execute small pieces of code at the edge. Dynamic acceleration helps even uncacheable requests by reusing established connections to your origin. For a small business owner, this means the CDN you choose is part of your security and uptime setup, not only a speed add-on.

It also means the cheapest way to get CDN caching is often not to buy it separately. Several managed hosts include an edge network and handle cache rules and purging for you.

Where hosting fits: edge caching you do not have to build

If you run a WordPress or WooCommerce site, you have three ways to get edge caching: assemble a CDN, a cache plugin and header rules yourself; use a host that bundles them; or both. The bundled route is where most owners should start, because the hard parts (excluding the cart from the cache, purging on update, keeping the cache key sane) are already configured for WordPress.

In our lab, we compare hosts on cold-cache TTFB, a 50-virtual-user load test and global latency, which shows how each stack behaves when the cache is empty and when traffic surges. Our WPX Hosting review covers a managed host we rate for speed and stability, and our Rocket.net review looks at a host built around an enterprise edge network. If you are still choosing, start with the ranked best managed WordPress hosting list.

Let our benchmarks pick the stack

Choosing a host with good caching starts with measured numbers, not feature lists. Our speed lab tests every host with purchased accounts and documented methods, and publishes cold-cache TTFB, load-test and global latency results side by side.

Sycamorenet

See the full results in our fastest web hosting benchmarks, or go straight to the managed WordPress hosting rankings if you want a shortlist.

A starting checklist

For a typical WordPress or WooCommerce site:

  • Cache public HTML, images, CSS and JS at the edge.
  • Exclude cart, checkout, account and any request with a login cookie.
  • Use long TTLs on versioned assets and purge on update for pages.
  • Strip marketing query strings from the cache key.
  • Set s-maxage for the CDN and a shorter max-age for browsers.
  • Verify hit status in developer tools, logged out and logged in.
  • Recheck after theme, plugin or host changes.

FAQ

What is CDN caching?

CDN caching is a CDN storing copies of your site’s files on servers near your visitors. When someone requests a file, the nearest server answers if it holds a fresh copy and only asks your origin server if it does not. That cuts load time and the work your host has to do.

Is a CDN just a cache?

No. Caching is one part. CDNs also handle encryption, DDoS protection, firewall rules, request routing and edge code, and they can speed up requests that cannot be cached. That is why picking one affects security and reliability as well as speed.

What happens if I clear the cache?

The stored copies are removed, so the next requests for those files go to your origin and refill the cache. Your site stays up, but it may feel slower for a short while, especially after a full purge on a busy site. Purge single URLs when you can.

How long should I cache content?

Match the lifetime to how often the content changes. Versioned CSS and JS can last a year, images weeks or months, and pages hours to days if you purge when you edit. Content that changes by the minute needs a lifetime of seconds or minutes, and personal pages should not be cached at all.

Why does my CDN keep showing a miss?

The usual causes are restrictive cache-control headers, a cache key fragmented by query strings or cookies, TTLs that are too short, or traffic too thin to keep objects warm. Check the response headers first, then the cache key, then the TTLs.

Similar Posts