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.
| Term | Meaning |
|---|---|
| Origin | Your own server or storage, where the real files live |
| Edge | A CDN server close to the visitor that answers on the origin's behalf |
| Cache hit | The edge already had a fresh copy and answered without asking the origin |
| Cache miss | The edge had nothing usable, fetched from the origin, then maybe stored it |
| Purge | Telling 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.
| Directive | Browser | CDN edge |
|---|---|---|
| max-age=N | Fresh for N seconds | Fresh for N seconds unless s-maxage is set |
| s-maxage=N | Ignored | Fresh for N seconds, overriding max-age |
| public | May store | May store, even with an Authorization header |
| private | May store | Must not store |
| no-store | Must not store | Must not store |
| immutable | Skips revalidation while fresh | Skips revalidation while fresh |
| stale-while-revalidate=N | May serve stale for N seconds while refreshing | Same, if the CDN supports it |
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
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.
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.
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.
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.
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.
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.
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.
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.