What Is a CDN and How Does It Speed Up Your Website
A CDN (Content Delivery Network) is a geographically distributed network of servers that delivers content to users from the nearest node. If your server is in Moscow and the user is in Vladivostok, a CDN allows content to be served from a server in Khabarovsk or Vladivostok, reducing latency by several times.
How a CDN Works
The principle behind a CDN is based on several key technologies:
Points of Presence (PoP)
A CDN consists of numerous servers (edge servers) located in data centers around the world. Each such data center is called a Point of Presence. Major CDN providers have hundreds of points of presence on every continent.
When a user requests a page, the CDN's DNS system routes them to the nearest edge server. The server selection is based on:
- Geographic proximity to the user
- Current server load
- Server health status (health checks)
- Network connectivity and latency
Content Caching
Edge servers store cached copies of content. On the first request, the CDN retrieves content from the origin server (your main server), stores it in cache, and serves it to the user. Subsequent requests are served from cache without contacting the origin.
Types of content cached by CDNs:
| Content Type | Cacheability | Notes |
|---|---|---|
| Images (JPG, PNG, WebP, AVIF) | Highly cacheable | Majority of traffic |
| CSS, JavaScript files | Highly cacheable | Use hashes in filenames |
| Fonts (WOFF2, WOFF) | Highly cacheable | Don't forget CORS headers |
| Video and audio | Well cacheable | Consider bandwidth |
| HTML pages | Conditionally cacheable | Depends on how dynamic the content is |
| API документацию responses | Partially cacheable | Only for GET requests with short TTL |
Pull vs Push Models
Pull model — the CDN fetches content from the origin server on the first request and then caches it. This is the most common model and is simple to set up.
Push model — you pre-upload content to CDN servers. This is suitable for large files (videos, distributions) where it is important to guarantee availability from the first request.
Benefits of a CDN
1. Reduced Latency
Physical distance between the client and server directly affects latency. The speed of light in fiber optics is approximately 200,000 km/s. The Moscow–Vladivostok route (~9,000 km) adds a minimum of 45 ms just for one-way signal transmission. Accounting for routing, real latency can be 100–150 ms one way.
A CDN reduces this latency to 5–20 ms by serving content from the nearest server. You can check your site's TTFB using the enterno.io HTTP header checker tool.
2. Reduced Origin Server Load
A CDN absorbs the bulk of traffic, freeing your server to handle dynamic requests. With proper configuration, a CDN can handle 90–95% of all requests without contacting the origin.
3. DDoS Protection
CDN providers have distributed infrastructure with enormous bandwidth. Cloudflare, for example, handles over 50 million HTTP requests per second under normal conditions. During a DDoS attack, traffic is absorbed by the CDN network before reaching your origin server.
4. Improved Availability
If one edge server goes down, traffic is automatically redirected to the next nearest server. Many CDNs guarantee an SLA of 99.99% or higher.
5. Automatic Optimization
Modern CDNs offer additional capabilities:
- Automatic image conversion to WebP/AVIF
- On-the-fly CSS and JavaScript minification
- Brotli/Gzip compression
- HTTP/2 and HTTP/3 support
- Automatic SSL certificates
Popular CDN Providers
Cloudflare
The most popular CDN with a free plan. In addition to CDN, it provides DNS, WAF, DDoS protection, Workers (serverless), and many other services. The free plan includes unlimited traffic, basic WAF, and SSL.
Fastly
A CDN with instant cache invalidation (purge in 150 ms). Used by GitHub, Reddit, and Pinterest. A powerful VCL platform for edge logic configuration, but more expensive than Cloudflare.
AWS CloudFront
Amazon's CDN, deeply integrated with the AWS ecosystem. An ideal choice if your infrastructure is already on AWS. Supports Lambda@Edge for serverless logic on edge servers.
Selectel CDN and CDNvideo
Russian CDN providers with points of presence in Russia and the CIS. They may be preferred for projects targeting a Russian audience for regulatory and low-latency considerations.
How to Set Up a CDN
Basic Setup
- Sign up with a CDN provider and add your domain
- Change DNS — point the domain to the CDN (usually by changing NS records or adding a CNAME)
- Configure the origin — specify the IP address or domain of your server
- Set up SSL — enable SSL/TLS проверку on the CDN (most providers offer a free certificate)
- Check headers — ensure that
Cache-Controlis configured correctly
Verifying CDN Operation
After setup, verify that the CDN is working correctly:
- Check the
ServerorCF-Ray(for Cloudflare) header using the enterno.io header analyzer - Ensure the
X-Cacheheader shows HIT for static resources - Compare TTFB before and after connecting the CDN
- Check DNS records via DNS Lookup — they should point to the CDN
Caching Configuration
Proper caching configuration is the key to CDN effectiveness:
# Example Cache-Control configuration in nginx
location ~* \.(jpg|jpeg|png|gif|webp|avif|svg|ico|css|js|woff2)$ {
expires 365d;
add_header Cache-Control "public, max-age=31536000, immutable";
}
location ~* \.html$ {
add_header Cache-Control "no-cache";
}
Edge Computing — The Future of CDN
Modern CDNs go beyond simple caching. Edge computing allows running code directly on edge servers, closer to the user:
- Cloudflare Workers — serverless functions on V8
- AWS Lambda@Edge — Node.js and Python on CloudFront
- Fastly Compute — WebAssembly at the edge
- Deno Deploy — JavaScript/TypeScript on a global network
This enables content personalization, A/B testing, authentication handling, and response transformation without contacting the origin server.
Common Mistakes When Using a CDN
- Caching personalized content — pages with user data (cart, account) should not be cached publicly
- No cache invalidation — after updating content, the old version may still be served from cache
- Incorrect CORS headers — fonts and API requests may be blocked
- Ignoring origin shield — without it, each PoP contacts the origin separately on a cache miss
- Mixed content — if the CDN works over HTTPS but the origin returns HTTP links
When You Don't Need a CDN
A CDN may be unnecessary if:
- Your audience is concentrated in one city, and the server is located there
- The site is entirely dynamic with no cacheable content
- Traffic is minimal (fewer than 1,000 visitors per day)
However, even in these cases, Cloudflare's free plan can provide benefits through SSL, attack protection, and DNS acceleration.
Try It Yourself
Check whether your site uses a CDN with the enterno.io HTTP header analyzer — look for the CF-Ray, X-Cache, X-CDN headers.
Check your website right now
Check now →