What is a CDN
A CDN (Content Delivery Network) is a network of servers (nodes, or PoPs — Points of Presence) distributed geographically around the world. When a user requests a resource, the CDN serves it from the server closest to the user instead of from the website’s origin server.
A CDN significantly reduces latency and TTFB, especially for users in other countries.
How a CDN works
Без CDN:
Пользователь (Москва) ────────────────────── Сервер (Франкфурт)
~30 мс RTT
С CDN:
Пользователь (Москва) ── CDN Edge (Москва) ── Origin (Франкфурт)
~3 мс RTT кеш файлов
Повторный запрос:
Пользователь (Москва) ── CDN Edge (Москва)
~3 мс RTT (без обращения к origin)
What CDNs cache
CDNs typically cache:
- Static files — CSS, JS, images, fonts
- Video and audio — streaming media
- Static HTML pages — SSG content
- API responses — when caching is configured
CDNs do not cache by default:
- Dynamic content (which depends on the user)
- POST requests
- Data for authenticated users
Popular CDN services
| Service | Features | Price |
|---|---|---|
| Cloudflare | Generous free plan + DDoS protection | Free / from $20/month |
| AWS CloudFront | AWS integration | Pay-per-use |
| Fastly | Instant cache invalidation | From $50/month |
| Bunny CDN | Low cost, good coverage | ~$0.01/GB |
| jsDelivr | Free for npm packages | Free |
Setting up Cloudflare CDN
- Sign up at cloudflare.com
- Add your domain
- Change your domain’s NS records to Cloudflare’s name servers
- Configure Page Rules for caching
// Заголовки для кеширования статики
Cache-Control: public, max-age=31536000, immutable
// для версионированных файлов (bundle.abc123.js)CDN and security
Cloudflare and other CDNs provide additional protection:
- DDoS protection — filtering malicious traffic
- WAF (Web Application Firewall) — blocking attacks
- Bot management — protection from scrapers
- SSL/TLS — free certificates and management
CDN cache invalidation
When you update files, you need to clear the cache:
# Cloudflare API
curl -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/purge_cache" \
-H "Authorization: Bearer TOKEN" \
-d '{"purge_everything": true}'Or use file versioning: bundle.v123.js — when a file changes, its name changes, so the old cache does not get in the way.
Checking HTTP/2 on reChecker
Use HTTP/2 & Brotli to check the protocol and compression on your website. Many CDNs enable HTTP/2 and Brotli automatically — this tool will confirm that they are working.
FAQ
Is a CDN essential for a small website? It is not essential, but it is useful. Even Cloudflare’s free plan speeds up your site and provides DDoS protection and free SSL — benefits worth using for any website.
Does a CDN hurt SEO? No. A CDN improves SEO by reducing TTFB and improving Core Web Vitals. Google considers loading speed a ranking factor.
What are “cache miss” and “cache hit”? A cache hit means the request was served from the CDN cache (fast). A cache miss means the CDN does not have the item cached, so the request goes to the origin server (slower). A high cache hit rate (90%+) is a CDN optimization goal.