GuidesHosting

CDN: what a content delivery network is for

By the Banzai Labs teamUpdated on 2 min read

A copy close to every visitorOrigin
A CDN keeps a copy of the site close to every visitor, and the origin serves it only once.

The principle

The first visit fills the cache, the next ones benefit
  1. VisitorRequests a page.
  2. CDN edgeThe nearest one. If it has the copy, it answers.
  3. OriginYour server, only asked when the copy is missing.

What to cache, and for how long

File Suggested duration Why
Versioned images, CSS, JS Very long The name changes with each version
HTML pages Short, or purge on publish They change without changing name
Personal API responses Never One visitor would see another’s data

The trap to avoid

Caching a page that depends on the user (cart, account). The rule: anything carrying a session cookie bypasses the cache.

See also hosting types and Core Web Vitals.

Frequently asked questions

Do I need a CDN for a local site?
Less so. If your visitors are close to your server, the distance gain is small. A CDN is still useful to absorb traffic spikes and filter attacks.
What happens when I publish a new version?
Copies must be refreshed. Versioned files (a name that changes on every build) are cached for a long time; HTML pages for a short time or with a purge.
Does a CDN protect against attacks?
Most filter flood attacks and offer a web application firewall. It is often the first reason to adopt one.

Read next

All guides