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.
| 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.
Cache-Control directives that matter at the edge
| 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 |
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
- Pick Cache-Control directives in the simulator to see whether a browser and a CDN edge may store the response, and for how long.
- Copy the resulting header line for your server or hosting config.
- Read the reference table to choose sensible values for HTML, hashed assets and private pages.
- After a deploy, purge the CDN or rely on new file names so visitors get the update.
Tips
- Give file names a content hash, such as app.3f9a1c.js, and cache them for a year with immutable. A new build produces new names, so nothing stale is served.
- Keep HTML on a short shared lifetime or revalidate it, because its URL never changes between releases.
- Never let a CDN store pages that show one person's account data. Mark them private or no-store.
- Loading a library from a public CDN does not save a repeat download any more: browsers now partition their cache per site for privacy.
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.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- Contact Us Page Examples: 6 Small-Business Designs Annotated | How-to Guide
- Content Approval Workflow for Websites: Who Signs Off, When, and How to Stop It Becoming a Bottleneck | How-to Guide
- Cookie Consent Banner Examples You Can Copy
- Copy to Clipboard Button (JavaScript and React)
- Core Web Vitals: LCP, INP and CLS, with 25 Fixes
- CORS Explained: Preflight, Headers and Fixing CORS Errors
- Crawled - Currently Not Indexed: Why Google Skipped Your Page
- "Crawled - Currently Not Indexed" on a Small Site: What to Do | How-to Guide
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App