+359 893 560 371 Support 24/7 · sales 9:00–18:00 All services operational
Hosting

What is a CDN, how it works and when you need one

What a CDN is, how a content delivery network works, what CDN caching is and how to purge it, when a CDN speeds up a website and when it does not, how it affects SEO and how to set one up step by step

The MaxBG team · 14 min read
What is a CDN, how it works and when you need one

You open a website hosted in Frankfurt on your phone in London, and the images appear instantly. The same site opened from Sydney should load noticeably slower, because the data travels halfway around the world. But if the site uses a CDN, the visitor in Sydney gets the images from a server in Australia and the difference almost disappears.

In this article you'll learn what a CDN is, how it works, what CDN caching is and how to manage it, and when a CDN really speeds up a website and when it's unnecessary. You'll also see how to set up a CDN step by step, how it affects SEO and the most common problems after switching it on.

In short

  • A CDN (Content Delivery Network) is a network of servers in many countries that keep copies of a website's files and deliver them from the location closest to the visitor.
  • A CDN doesn't replace hosting. The site still lives on your server, and the CDN sits in front of it as a fast intermediate layer.
  • The CDN cache keeps ready copies of files for a set time (TTL), and when something changes, the cache is purged manually or automatically.
  • The biggest benefit is for sites with visitors from many countries, heavy images and video, or large traffic spikes.
  • A CDN is usually switched on by changing DNS records, without moving the website.

What is a CDN

A CDN (Content Delivery Network) is a group of servers located in different cities and countries that work together to deliver a website's content faster. Each of these servers keeps copies of the site's files: images, stylesheets, scripts, fonts, videos and sometimes entire pages.

When someone opens the site, the files don't come from your hosting server but from the CDN server closest to the visitor. The route is shorter, so the page loads faster. Your server is called the origin, and the CDN's servers are called edge servers because they sit at the "edge" of the network, close to users. The places where they are located are called points of presence, or PoPs.

Large CDN networks have points of presence in hundreds of cities around the world. So a visitor from Manchester, Munich and Toronto gets the same files, but each from a different server close to them.

How a CDN works – infographic with the network of edge servers and the five delivery steps

How a CDN works

The most common model is called a pull CDN: the network "pulls" files from your server itself the first time someone requests them. Here's what happens during a visit:

  1. The visitor opens the site. The browser asks DNS which IP address belongs to the domain. If the site is behind a CDN, DNS returns the CDN's address, not your server's.
  2. The request reaches the nearest edge server. The network automatically routes the visitor to the closest or least busy point of presence.
  3. The edge server checks its cache. If it has a fresh copy of the file, it returns it straight away. This is a cache hit, and your server isn't involved at all.
  4. If there's no copy, the edge server asks the origin. This is a cache miss. The file is fetched from your hosting, returned to the visitor and stored in the cache for the next ones.
  5. Subsequent visitors from the same region get the file directly from the edge server until the copy goes stale or is purged.

There's also a push CDN, where you upload files to the CDN yourself, in advance. It's used mainly for large files such as videos and installation packages. For an ordinary business website or online shop, the pull model is more convenient because it needs no maintenance.

Pull vs push CDN – how files reach the edge servers

What is a CDN cache

The CDN cache is the temporary storage on the edge servers where ready copies of files are kept. It's the reason a CDN is fast: a file that's already in the cache is returned in milliseconds, without waiting for your server.

Every copy has an expiry time called TTL (Time to Live). When it runs out, the edge server asks the origin whether the file has changed. If it hasn't, the copy is renewed without downloading it again. If it has, the new version is fetched.

How long a file is kept is determined mainly by the Cache-Control HTTP header your server sends. For example, Cache-Control: public, max-age=31536000 says the file can be cached for a year. That suits images and files with a version in their name, such as style.4f2a.css. In the dashboard of most CDN services you can also set your own rules that override the server's.

Whether a file came from the cache is shown in the response headers. On Cloudflare it's CF-Cache-Status; on other services it's usually X-Cache. These are the values you'll see most often:

StatusWhat it means
HITThe file was returned from the CDN cache; your server wasn't touched.
MISSThe file wasn't in the cache, was fetched from your server and is now stored.
EXPIREDThe copy was in the cache, but its time ran out and it was fetched again.
BYPASSThe cache was deliberately skipped, for example because of a login cookie or a rule.
DYNAMICThe file isn't considered cacheable and always comes from the server.

When you replace an image or a stylesheet and can't see the change, the cause is almost always the cache. You then purge it: for a specific URL, for a group of files or for the whole site. Purging the entire cache is easy, but for a few minutes it puts load on your server because every file is fetched again.

What a CDN caches and what it doesn't

A CDN is most useful for static files that are the same for every visitor:

  • Images and graphics: JPG, PNG, WebP, AVIF, SVG. They're usually the largest part of a page's weight.
  • Stylesheets and scripts: the CSS and JavaScript files of your theme and plugins.
  • Fonts: WOFF2 and other formats that would otherwise be downloaded on every new visit.
  • Videos and downloads: PDF catalogues, archives, price lists.

HTML pages are more delicate. Many CDN services don't cache HTML by default, because it can differ for each visitor. A blog or service page can safely be cached. The cart, the account page, the checkout and anything that depends on a login or a cookie must never go into the shared cache. Otherwise one customer may see another customer's details or cart.

What a CDN caches – static files in the shared cache and personal pages kept out of it

Benefits of a CDN

  • Faster loading for distant visitors. The further the visitor is from the server, the bigger the gain.
  • Less load on your hosting. With a high cache hit ratio, your server handles only a small share of requests and has more capacity for dynamic pages.
  • Resilience during spikes. A campaign, a post that goes viral or a TV advert won't bring the site down, because the CDN absorbs the static traffic.
  • Less bandwidth from your server. If your hosting has a transfer limit, a CDN saves it.
  • Extra protection. Many CDN networks filter malicious traffic and absorb part of DDoS attacks before they reach your server. You can read more about the attacks themselves in our article what is a DDoS attack.
  • Modern protocols with no setup. HTTP/2, HTTP/3 and compression such as Brotli are usually enabled by default.

When a CDN makes little sense

A CDN isn't a magic speed button. If almost all your visitors are in one country and the site is on a server in that country or a neighbouring one, the data's route is already short. The gain from a CDN is then small and sometimes barely noticeable.

A CDN won't fix a slow server either. If a page takes three seconds to generate because of heavy plugins or an overloaded database, a CDN will speed up the images but not the page itself. So first find out where the slowness comes from. We show how in our article on website speed.

CDN vs hosting: what's the difference

Hosting is where the website lives: the files, the database, PHP, email. Without hosting there is no website. A CDN is an extra layer in front of the hosting that delivers copies of the files faster. Without a CDN the site works normally. Without hosting the CDN has nothing to deliver.

So the two don't replace each other; they complement each other. If you're just choosing, start with hosting, because it determines how quickly your pages are generated. We explain what it includes and how it works in our article what is web hosting. Add a CDN later if your visitors or traffic justify it.

CDN vs hosting – the website server and the CDN layer in front of it

How a CDN affects SEO

A CDN isn't a ranking factor in itself, and Google won't move you up just because you use one. The impact is indirect, but real.

Faster loading improves your Core Web Vitals, especially LCP, which measures how quickly the main content appears. A shorter response time (TTFB) for distant visitors helps both users and crawlers. On a large site, faster responses mean Googlebot can crawl more pages in the same time.

There are also risks to avoid. If the CDN blocks Googlebot by mistake, for example because of overly strict bot protection, pages can drop out of the index. If images move to a separate subdomain such as cdn.example.com, check that the URLs on the site and in the sitemap are correct. The good news is that with a CDN in front of the whole domain, URLs don't change at all.

How to set up a CDN

There are two main ways. In the first, the CDN sits in front of the whole domain. That's how Cloudflare works: you replace the domain's DNS servers with the CDN's, and it starts handling all the traffic. In the second, you create a subdomain such as cdn.example.com, point it to the CDN with a CNAME record, and change the URLs of images and stylesheets on the site to use it. If DNS records are new to you, read our article what is DNS first.

This is what the first option looks like step by step:

  1. Sign up with the CDN service and add your domain.
  2. Check the DNS records the service has detected automatically. Compare them with those at your current DNS provider, especially the email records (MX, SPF, DKIM), so your email doesn't stop.
  3. Change the nameservers at your domain registrar to the ones the CDN service gives you. The change usually takes effect within minutes to a few hours.
  4. Turn on HTTPS and choose a mode where the connection between the CDN and your server is encrypted as well. On Cloudflare this is Full (strict) mode, and your server needs a valid SSL certificate.
  5. Set cache rules: which paths to cache and which never to cache, such as /wp-admin/, the cart and the account page.
  6. Check the result. Open the site in a private window, look at the requests in the developer tools and look for the HIT value in the headers.

For WordPress, most caching plugins have a built-in connection to popular CDN services and can purge the cache automatically when you publish or edit a post.

How to set up a CDN – DNS, HTTPS and cache rules

How to choose a CDN

The best-known services are Cloudflare, Bunny CDN, Amazon CloudFront and Fastly. Cloudflare has a free plan that covers the needs of most small and medium-sized websites. Bunny CDN charges for the traffic you actually use and often works out cheap. CloudFront and Fastly suit larger projects with a technical team. When choosing, look mainly at:

  • Where the points of presence are. It matters that there are servers where your visitors are.
  • How you pay. A free plan, a fixed monthly fee or pay-as-you-go by traffic.
  • How easy it is to manage the cache. Path-based rules, quick purging, WordPress integration.
  • What protection is included. A web application firewall (WAF), bot filtering, DDoS protection.

Common problems after switching on a CDN

  • Changes don't show up. The old copy is still in the cache. Purge the cache for that URL or add a version to the file name.
  • A logged-in user sees someone else's session or cart. This is the most dangerous problem, and it comes from cached HTML of personal pages. Exclude every page with a login, a cart or a checkout from the cache.
  • A mixed content warning. Some files still load over HTTP. Change their URLs to HTTPS.
  • Fonts don't load from the subdomain. The browser blocks them because of CORS. You need a header that allows them to load from your domain.
  • An endless redirect loop. Usually the CDN's SSL mode doesn't match the server's settings. Use an encrypted connection on both sides.
  • The server is exposed despite the CDN. If the server's real IP address is visible in old DNS records or in email headers, attackers can bypass the CDN. Don't publish it, and accept web traffic only from the CDN's addresses.

Common CDN problems – stale cache, mixed content and an exposed IP address

Frequently asked questions

What is a CDN in simple terms?

A CDN is a network of servers in different countries that keep copies of your website's files and deliver them from the location closest to the visitor. The site loads faster, and your server carries less load.

Do I need a CDN if my customers are only in one country?

Usually it isn't essential. If the server is in the same country or nearby, the route is short and the gain is small. A CDN is still worth it if you have lots of heavy images and video, expect big traffic spikes or want extra protection.

Is a CDN free?

There are free plans, the best known being Cloudflare's. They cover the needs of most small websites. Paid plans add more cache rules, better protection and support.

Does a CDN replace hosting?

No. The website stays on your hosting, and the CDN delivers copies of its files. If the hosting goes down, the CDN may show cached copies for a short while, but the site won't work normally.

What do CDN cache HIT and MISS mean?

HIT means the file was returned from the CDN cache without asking your server. MISS means the file wasn't in the cache and was fetched from the server. After the first MISS the file is stored, and later requests are usually HITs.

How do I clear the CDN cache?

In the CDN service's dashboard you choose to purge a specific URL or the entire cache. Many WordPress plugins do this automatically when you publish or edit content.

Does a CDN help SEO?

Indirectly. A CDN isn't a ranking factor, but faster loading improves Core Web Vitals and the user experience, which Google takes into account. It's important that the CDN doesn't block Googlebot.

Can a CDN stop a DDoS attack?

A large CDN network absorbs and filters a large share of attacks before they reach the server. The protection only works if the server's real IP address stays hidden and all traffic is forced through the CDN.

Conclusion

A CDN is a network of servers that deliver your website's files from the location closest to the visitor. It speeds up the site for distant visitors, takes load off your hosting, withstands spikes and adds protection. It doesn't replace good hosting and won't fix slow page generation, but on top of a fast server it adds exactly the extra speed and security that make the difference as your traffic grows.

A CDN works best on top of a fast server. Start with hosting that generates pages quickly, and add a CDN when your visitors come from many countries. It plugs into any hosting through DNS, without moving the website.

See the hosting plans · How to speed up your website

AI assistant instant answers, 24/7
🍪 We use cookies

To keep MaxBG fast and secure, we use essential cookies. With your consent we also add Google tools (Analytics and Ads). They help us analyse visits and improve our hosting services, and the data is shared securely with Google. You can change your choice or learn more in our Cookie policy