Performance glossaryA content delivery network (CDN) is a worldwide network of servers that store copies of a site's files and serve each visitor from a nearby location. Pages load faster as a result.
A content delivery network (CDN) is a set of servers spread across many cities, usually called edge servers or points of presence. Instead of every visitor fetching every file from the one server that hosts a site (the origin), visitors are served from the nearest edge server, which keeps a cached copy. Shorter distances mean less network latency, so files arrive sooner.
How a CDN works
- A visitor requests a file, such as an image or a stylesheet, and DNS or anycast routing sends the request to a nearby edge server.
- If the edge server has a fresh copy (a cache hit), it sends it straight away.
- If not (a cache miss), it fetches the file from the origin, sends it on, and keeps a copy for the next request.
How long copies are kept depends on the origin's Cache-Control headers and the CDN's own rules. Most CDNs today work this way, pulling files from the origin on demand; older "push" CDNs needed files uploaded to them in advance.
What a CDN does for a site
- Faster delivery of images, CSS, JavaScript, fonts, and video, especially for visitors far from the origin.
- Less load and bandwidth on the origin server, since most static requests never reach it.
- Resilience during traffic spikes, because the edge absorbs much of the traffic.
- Security features at many providers, such as DDoS mitigation and a web application firewall.
- Modern delivery: most CDNs handle HTTPS, HTTP/3, and Brotli compression on the origin's behalf.
A CDN does not fix a slow origin on its own. If HTML pages are not cached at the edge, every page view still waits for WordPress to build the page, so server response time still matters.
Setting up a CDN on WordPress
There are two common setups:
- Full proxy. The domain's DNS points to the CDN, which sits in front of the whole site. Cloudflare works this way. Static files are cached automatically, and HTML can be cached too, with WordPress-aware rules that bypass logged-in users, carts, and checkout.
- Asset CDN. The site stays where it is, and a plugin or the host rewrites the URLs of images, CSS, and JavaScript to a CDN hostname such as
cdn.example.com.
Many managed WordPress hosts include a CDN, so it is worth checking before adding another.
How to check it is working
In the browser's developer tools, look at the response headers of an image or stylesheet. Headers such as cf-cache-status: HIT or x-cache: HIT, or an age value, show the file came from the CDN's cache. A repeated MISS means the file is not being cached. There is a fuller walkthrough in how to check if a CDN is working.
Common mistakes
- Caching HTML for logged-in users or WooCommerce carts, which can show one visitor's details to another.
- Forgetting to purge the CDN after changes, so old files keep being served.
- Expecting a CDN to rescue an overloaded origin when the real problem is slow, uncached page generation.
Source: MDN: CDN.