The Problem: Network Latency
When a visitor in Tokyo loads your site hosted in France, each request physically travels thousands of kilometers through undersea cables. This distance introduces unavoidable network latency: roughly 200 to 300 ms round-trip. Even with an optimized server, you cannot overcome the laws of physics.
This delay directly affects TTFB (Time To First Byte — the time before receiving the first byte of data), a key metric for Google and for user experience.
How a CDN Works
A CDN (Content Delivery Network) is a network of geographically distributed servers called PoPs (Points of Presence). Each PoP stores a copy of your static files: images, CSS stylesheets, JavaScript files, and fonts.
When a visitor requests a resource, the CDN automatically routes them to the nearest PoP. Instead of 300 ms from Tokyo to Paris, the response comes from a server in Osaka in just 10 ms.
Two outcomes are possible:
- Cache-hit: the file is already on the PoP and is served immediately.
- Cache-miss: the file is not yet cached, so the PoP fetches it from your origin server (your host) and stores it for future requests.
Static vs Dynamic Content
CDNs excel with static content: images, CSS, JS, videos, and fonts. These files are identical for all visitors and can be cached without restriction.
Dynamic content (personalized pages, e-commerce carts, real-time data) is more complex. Some advanced CDNs offer edge computing (running code at the PoP level) to accelerate this type of content as well, but configuration is more involved.
TTL and Cache Purging
TTL (Time-To-Live) defines how long a file remains on Edge servers before being refreshed. A long TTL (e.g., 1 year for a versioned file) maximizes cache-hits. A short TTL ensures content freshness.
Cache purging (or invalidation) forces a file to be reloaded across all PoPs without waiting for TTL expiration. Modern CDNs propagate purges globally within seconds.
HTTP Cache-Control headers govern this behavior:
Cache-Control: public, max-age=31536000, immutable
public: allows caching by proxies and CDNs.max-age=31536000: one-year TTL in seconds.immutable: signals the file will never change (for versioned assets).
CDN and Security
Major CDNs include built-in security protections. DDoS (Distributed Denial of Service) mitigation absorbs volumetric attacks using the massive network capacity of PoPs. Some also include a WAF (Web Application Firewall) that filters malicious requests before they reach your server.
Available Solutions
Several options are available depending on your budget:
- Cloudflare Free: free, easy to configure, PoPs in over 300 cities. Ideal for most websites.
- Amazon CloudFront: integrated with the AWS ecosystem, pay-as-you-go pricing, highly flexible.
- Fastly: developer-focused, advanced configuration, near-instant cache purging.
The performance impact is significant: TTFB (Time To First Byte) can be reduced by 50 to 80% for visitors far from the origin server.
Check Your CDN Configuration
Incorrect CDN configuration can negate all benefits: TTL too short, missing Cache-Control headers, or dynamic content accidentally cached. Run a free audit to analyze your HTTP headers, verify your cache policies, and identify unoptimized resources.