GuidesHosting
CDN: what a content delivery network is for
The principle
- VisitorRequests a page.
- CDN edgeThe nearest one. If it has the copy, it answers.
- 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.