What is a CDN and do you need one?

A CDN keeps copies of your site on servers worldwide so visitors load it from nearby. What it speeds up, what it cannot fix, and how to tell if you need one.

BeginnerExplainer9 min readUpdated October 30, 2026

In this guide
  1. The problem a CDN solves
  2. How a CDN works
  3. What a CDN speeds up, and what it cannot
  4. Do you need one?
  5. Three ways to start
  6. Settings that decide whether it works
  7. Image CDNs
  8. Library CDNs are a different thing
  9. Choosing a CDN
  10. Check that it works
  11. Check your own page
  12. Sources

The problem a CDN solves

A browser cannot show your page until data has crossed the distance between your server and the visitor. Every request makes a round trip, and distance adds delay to each one. MDN puts it plainly: geographic distance affects latency proportionally. The first request is the worst. Before the first bytes can flow, the browser has to look up the address, open a connection and secure it, and each step is another trip. Later requests reuse the connection and cost less.

You cannot make data travel faster, so the fix is to shorten the distance. If your server is in one city and a visitor is on another continent, every file takes the long way. A CDN puts copies of the files on servers near the visitor, so most requests take a short trip.

How a CDN works

How a CDN answers a request. The visitor asks the CDN server nearest to them. If that server holds a fresh copy, it answers at once. If it does not, it asks your own server, the origin, passes the answer on and keeps a copy for the next visitor. 1 · The visitorAsks for a page or a file 2 · The CDN server nearest to themLooks for a fresh copy of what was asked for Copy found: a hitIt answers at once,from close by. No copy: a missIt asks your server,the origin. 3 · Your serverBuilds or reads the file. The CDN keeps a copy. The next visitor nearby gets a hit.
A visitor's request goes to the nearest CDN server. A hit is answered there; a miss goes to your server, and the CDN keeps the answer.
  1. Your address points at the CDN. Setup usually means signing up and changing a DNS record so that your web address leads to the CDN. From then on, visitors connect to a CDN server instead of yours.
  2. The visitor reaches a nearby CDN server. CDN companies run many of these servers in cities around the world. They are often called edge servers.
  3. The edge server checks for a fresh copy. If it has one, it answers at once. This is a cache hit.
  4. If it has none, it asks your server. Your server is the origin. This is a cache miss. The edge server passes your answer to the visitor and, if your headers allow it, keeps a copy.
  5. The next visitor nearby gets a hit. The copy stays until its lifetime ends, until the CDN needs the space, or until you clear it.

The most common way to fill the copies is the one above, called origin pull: the CDN fetches a file the first time someone asks for it. Clearing a file before its lifetime ends is called purging, and CDNs usually offer it through an API. Which files the CDN keeps, and for how long, is decided by the cache headers your server sends. See HTTP caching headers.

What a CDN speeds up, and what it cannot

Part of your siteDoes a CDN help?Why
Images, stylesheets, scripts and fontsYes, a lotThey are the same for everyone and can be kept for a long time
Public pages that look the same to everyoneYes, when the CDN is allowed to cache themThe page is answered nearby and your server is not asked
Pages that differ per visitor, such as a cart or an accountSomeThey cannot be shared, but the connection is still shorter
A slow application behind the CDNOnly on a hitA miss still waits for your server
Heavy JavaScript, large images, render-blocking filesNoThe bytes still have to arrive, be parsed and run
Third-party scripts such as chat and trackingNoThey come from other companies' servers

The third row surprises people. web.dev explains that even content a CDN cannot keep is usually faster through one. The visitor opens a connection to a server close by, and the rest of the trip runs over the CDN's own network, which often keeps connections to your server open already.

Many CDNs add more than copies:

Do you need one?

Use this table as a first answer.

Your situationA CDN is probably
Visitors in several countries or continents, and one serverA big gain
Traffic that arrives in waves, such as campaigns or seasonsWorth it, because it takes load off your server
A page full of images, video or large downloadsA big gain
A store or site with loginsWorth it for the static files; HTML needs care
A small local business with all visitors close to the server, and a working page cacheA small gain, but often free
An application whose pages cannot be shared at allLimited to the files and the shorter connection

Cost is less of a barrier than it was. The 2025 Web Almanac found CDN use on 71% of the top 1,000 sites and on 35% of the top 10 million, and it credits free and low-cost plans, and hosts that bundle a CDN, for the growth among smaller sites. Before you buy one, ask your host whether it already runs one in front of your site.

A CDN is not a replacement for a good server. On a hit it hides a slow server. On a miss, which is every first request and every request for a page that cannot be kept, your server is still the one that has to answer. Work on the first byte as well.

Three ways to start

  1. Static files only. Put your images, scripts, styles and fonts on a CDN, either through a separate address such as static.example.com or through your platform's setting. This is the lowest-risk step.
  2. The whole site. Point your main address at the CDN. Static files are usually kept without further settings. Whether pages are kept depends on the CDN and on your headers, and the CDN still gives you the shorter connection for the pages it cannot keep. web.dev's advice is to deliver as much of the site as possible through the CDN.
  3. Public pages cached too. Let the CDN keep your HTML, and clear it when you publish. This is where most of the TTFB gain is, and where most of the mistakes happen. The next section covers the rules.

Settings that decide whether it works

A CDN with the wrong settings is a slower, more expensive copy of your server. These are the settings that matter.

Image CDNs

An image CDN is a CDN that also changes images for you. The address of the image carries the size, format and quality you want, and the service creates and keeps each version. Some can choose the best format for each browser automatically. web.dev says that switching to an image CDN can save 40% to 80% of image bytes. The workflow is covered in image optimization and the formats in WebP and AVIF.

Library CDNs are a different thing

Some sites load jQuery, Bootstrap or fonts from a public CDN address, hoping visitors already have the file from another site. That no longer works. Browsers now separate their caches by the site being visited, so a file fetched for one site is not reused for another. MDN lists the HTTP cache, the image, script, stylesheet and font caches among those that are partitioned. The visitor pays for an extra connection and gets no sharing. MDN's glossary also notes that such a CDN adds a dependency on another company and another way to be attacked. Serving the files from your own address, or from your own CDN, avoids the extra connection.

Choosing a CDN

Compare these points rather than brand names:

Check that it works

  1. Look at the headers. Many CDNs add a header that says whether an answer was a hit or a miss. The name differs by company, so check its documentation. An Age header above zero also shows that a shared cache held the copy.
  2. Request twice. The first request to a file may be a miss. The second should be a hit.
  3. Test from far away. Run a speed test from a location near your visitors, not only from your own city.
  4. Watch the real numbers. After the change, follow the first-byte time in real-user data. Lab data and field data explains why that is the number to trust.
  5. Look at the dashboard. The hit ratio should climb in the first days and settle.

Check your own page

Run the free audit and look at the server response time and the cache lifetimes of your files. A long wait for a page that is the same for everyone, or a list of files with short lifetimes, are the two signs that a CDN, or better settings on the one you have, will help. If the audit shows a good first response already, spend your time on the biggest items in the report instead.

Sources

Start here

Free website audit

Live Google data for any public page: mobile and desktop.

Mobile + desktop · Lighthouse lab test · Real-user Chrome data when Google has it

Rather have this done for you? Speed optimization · Book a call

Related guides

All guides →