What a CDN Does, Explained Plainly

A content delivery network is a set of servers spread around the world that keep copies of your site's files. Visitors are answered by a nearby edge server instead of your origin, so pages load with less waiting, and your own server handles far fewer requests. Cache-Control headers decide what the edge may store.

CDN words in one line each
TermMeaning
OriginYour own server or storage, where the real files live
EdgeA CDN server close to the visitor that answers on the origin's behalf
Cache hitThe edge already had a fresh copy and answered without asking the origin
Cache missThe edge had nothing usable, fetched from the origin, then maybe stored it
PurgeTelling the CDN to drop stored copies so the next request fetches new ones

Updated

Distance costs time on the internet: every new connection needs several round trips before the first byte arrives. A CDN shortens those trips by answering from somewhere near the reader. This guide covers how that works, what it cannot do, and how your headers control it, with a simulator you can try.

Cache-Control directives that matter at the edge

What each directive tells browsers and CDNs
DirectiveBrowserCDN edge
max-age=NFresh for N secondsFresh for N seconds unless s-maxage is set
s-maxage=NIgnoredFresh for N seconds, overriding max-age
publicMay storeMay store, even with an Authorization header
privateMay storeMust not store
no-storeMust not storeMust not store
immutableSkips revalidation while freshSkips revalidation while fresh
stale-while-revalidate=NMay serve stale for N seconds while refreshingSame, if the CDN supports it

Header recipes by file type

Three common policies

Hashed assets live for a year, HTML refreshes at the edge every minute, and account pages never touch a shared cache.

# /assets/app.3f9a1c.js (file name changes every build)
Cache-Control: public, max-age=31536000, immutable

# /index.html and other pages
Cache-Control: public, max-age=0, s-maxage=60, stale-while-revalidate=300

# /account (different for each signed-in person)
Cache-Control: private, no-store

What happens on a request

The visitor's resolver returns the address of a nearby edge. The edge checks its store for the URL. On a hit it answers straight away; on a miss it asks your origin, passes the reply on, and keeps a copy if the headers allow it.

Edges also keep warm connections open to the origin, so even a miss is often quicker than a visitor connecting to your server from the other side of the world.

What a CDN cannot fix

Slow database queries, heavy JavaScript and oversized images are still slow when served from an edge. A CDN removes distance, not work.

It also adds one more thing to fail. If the CDN has an outage, every site behind it is affected, so status pages and a plan for that case are worth having.

How it works

  1. Pick Cache-Control directives in the simulator to see whether a browser and a CDN edge may store the response, and for how long.
  2. Copy the resulting header line for your server or hosting config.
  3. Read the reference table to choose sensible values for HTML, hashed assets and private pages.
  4. After a deploy, purge the CDN or rely on new file names so visitors get the update.

Tips

Frequently asked questions

Does a CDN make every site faster?

Usually, for visitors far from your server, because round trips are shorter and connections are set up nearby. It can add cost when it introduces an extra domain to look up and connect to, which is why serving everything from your own domain through the CDN is better than mixing hosts.

What is s-maxage?

A Cache-Control directive that sets the freshness lifetime for shared caches such as CDNs only. It overrides max-age at the edge while browsers keep using max-age, so you can let the edge keep a page for an hour and the browser for a minute.

Can a CDN cache dynamic pages?

Yes, if the response is the same for everyone. Even a few seconds of caching can absorb a traffic spike. Responses that differ per signed-in user must not be stored in a shared cache.

Is a CDN a security risk?

It is another party in the path of your content. If you load scripts from a third-party CDN, add a Subresource Integrity hash so the browser refuses a file that has been altered.

Do I need to add a CDN myself?

Many hosting platforms already serve published sites through a CDN. Read your host's documentation before putting a second one on top, since two layers of caching make purges and debugging harder.

Related: How to optimize website speed, Core Web Vitals, PageSpeed Insights explained, DNS record types, Bunny CDN integration.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap