- What is a CDN?A content delivery network is a group of servers spread across many locations.
- How does a CDN work step by step?Their browser asks for an image or script on your domain.
- What does a CDN cache?By default, static files: images, CSS, JavaScript, fonts and downloads.
What is a CDN?
A content delivery network is a group of servers spread across many locations. Instead of every visitor connecting to your one hosting server, the CDN answers from the server nearest to them, which shortens the distance data travels. Your own server, called the origin, is contacted only when the CDN does not have a fresh copy.
The distance matters because every round trip between a visitor and a server takes time, and time zones away adds up. A page needs many requests: HTML, stylesheets, scripts, fonts and images. Serving most of them from a nearby location removes a large share of that delay.
How does a CDN work step by step?
- The visitor requests a file
Their browser asks for an image or script on your domain.
- The nearest edge answers
If it has a cached copy, it sends it at once.
- The origin is asked only if needed
On a cache miss, the edge fetches the file from your host and keeps a copy.
- Later visitors get the cached copy
Until it expires or you purge it.
What does a CDN cache?
By default, static files: images, CSS, JavaScript, fonts and downloads. These rarely change, so they are safe to keep for days or weeks. Some CDNs can also cache whole HTML pages for visitors who are not logged in, which is how a busy WordPress site survives a traffic spike. Pages that depend on the user, such as carts, checkouts and account pages, must not be cached or must be cached per user.
You control caching with HTTP headers such as Cache-Control, which tell a CDN and browsers how long a file is valid. The MDN documentation on HTTP caching explains these headers in detail.
What is the difference between a CDN and web hosting?
A CDN does not replace hosting. It sits in front of it. Some hosts bundle one; others expect you to add one such as Cloudflare, covered in do you need Cloudflare?.
| Web hosting | CDN | |
|---|---|---|
| Stores your site files | Yes, the originals | Copies, temporarily |
| Runs your code and database | Yes | No |
| Where it sits | One or a few locations | Many locations worldwide |
| Main job | Run the site | Deliver files fast and absorb load |
| Can you use one without the other? | Yes | No, a CDN needs an origin |
What are the benefits?
- Speed for visitors far from your server, especially on image-heavy pages.
- Less load and lower data transfer on your host; see bandwidth, storage and data transfer.
- Resilience: many CDNs absorb traffic spikes and filter attacks, which overlaps with DDoS protection and a web application firewall.
- Modern protocols such as HTTP/3 and compression handled for you; see HTTP/3 and hosting.
- Often a free tier for small sites.
What are the downsides and risks?
- Stale content: cached files can show old versions until you purge or they expire.
- A misconfigured cache can leak personalised pages, a serious problem. Exclude logged-in and cart pages.
- SSL settings must agree between the CDN and your origin, or you can create redirect loops; see what an SSL certificate is.
- Real visitor IP addresses may be hidden from your logs unless you configure the forwarding header.
- Another vendor to depend on.
Does a CDN improve time to first byte?
For cached files, yes: the response comes from nearby, so the first byte arrives sooner. For uncached dynamic pages, no: the request still has to reach your origin, and the CDN adds only a small hop. If your problem is a slow server, a CDN will hide part of it for cached content but will not fix it. Read what TTFB is to separate the two.
Who needs a CDN?
Sites with visitors in several countries, image-heavy pages, large downloads and sites with traffic spikes gain the most. A local business whose visitors are all near the server gains less, but the free tier of many CDNs is still worth turning on for the security and compression features. Shops and busy WordPress sites benefit the most because they serve many assets per page.
How do you choose a CDN service?
A CDN service is the company that runs the network, and the choice matters less than turning one on correctly. Compare services on the points below rather than on a headline price, and read each provider’s own documentation for the current numbers.
| What to check | Why it matters |
|---|---|
| Pricing model | Some charge per gigabyte delivered, some per request, some a flat monthly fee. A small site on a free tier pays nothing; a download-heavy site can pay a lot. |
| Locations near your visitors | A network with servers close to your audience does more for speed than a network with more locations elsewhere. |
| Cache control | You need to set how long files are kept and to clear a file when you change it. |
| HTTPS and protocols | Look for free certificates, HTTP/2 and HTTP/3 support. |
| Security extras | Many CDN services add DDoS protection and a web application firewall; check what is included and what costs extra. |
| Setup effort | A CDN built into your host needs no DNS changes; a separate service usually needs DNS or nameserver changes. |
| Support and limits | Check the free tier’s limits, how support works and how easy it is to switch away. |
If your host already includes a CDN, start there and measure before adding another service. See do you need Cloudflare? for the most common separate option, and what is time to first byte for a measurement that shows whether a CDN helped.
How do you set up a CDN?
There are two common methods. A CDN built into your host is switched on in the control panel and needs no DNS changes. A separate CDN either acts as a reverse proxy (you point your nameservers or DNS records at it) or serves a dedicated asset hostname such as cdn.example.com that you reference in your pages. After setup, test that pages still load over HTTPS, that logged-in pages are not cached, and that updated files appear after you purge. Our nameservers guide covers the DNS side.
A worked example: what a CDN does to a page’s requests
A page needs 40 requests: one HTML file, five scripts, three stylesheets, two fonts and 29 images. Without a CDN, a visitor in another continent sends all 40 requests to your origin, each taking a long round trip. With a CDN in front, the HTML is sometimes served from the edge too, and the 39 static files come from a server a few milliseconds away. The origin only sees the requests the CDN could not answer, such as personalised pages.
The page may finish loading in under two seconds instead of five for that visitor, and your host handles a small fraction of the original load. This is the typical gain: it is large for distant visitors and image-heavy pages, and small for a local audience on a lightweight site.
What cache rules should you set first?
| Content | Suggested rule |
|---|---|
| Images, fonts, scripts and styles | Cache for a long time, version file names when they change |
| Public HTML pages | Cache for a short time, purge on update |
| Cart, checkout and account pages | Do not cache |
| Admin and login pages | Do not cache, restrict access |
| API responses | Cache only if safe and public |
Does a CDN help SEO?
Not directly. A CDN is not a ranking factor. It helps indirectly, because faster loading improves how people experience your pages, and Core Web Vitals, such as Largest Contentful Paint, are part of Google’s page experience signals; see web.dev. Faster pages can also reduce bounces. A CDN also adds resilience: a site that stays up during a spike is crawled and used normally. Be careful with configuration: serve the same content to crawlers and visitors, keep canonical URLs on your own domain, and make sure the CDN does not block legitimate crawlers.