What Is a CDN and Why Does Your Website Need One?

A Content Delivery Network (CDN) can be the single biggest performance improvement you make to your website. Learn how CDNs work, what they cache, and how they can make your site load in milliseconds for users around the world.

What Is a CDN?

The speed of light is the bottleneck nobody talks about. A request from Tokyo to a server in New York takes at minimum 70–80 ms for the round trip — that's physics, not code. A CDN puts cached copies of your content in data centers around the world so that round trip shrinks to single-digit milliseconds for most users.

The speed of light is a hard limit. A request from Tokyo to a server in New York takes at minimum 70-80 milliseconds just for the round trip, due to the physical distance the data must travel. A CDN with edge nodes in Tokyo means that same user gets content from 5 milliseconds away instead.

How Does a CDN Work?

The process works through DNS resolution and caching. When you put your website behind a CDN, your domain's DNS records point to the CDN instead of your server. When a user visits your site:

  1. Their browser queries DNS for your domain
  2. The CDN's DNS system returns the IP address of the nearest edge node
  3. The browser connects to that edge node
  4. If the content is cached, the edge node serves it immediately
  5. If not cached (cache miss), the edge node fetches it from your origin server, serves it to the user, and caches it for future requests

After the first visitor requests a page, all subsequent visitors from that region get the cached version — without touching your server at all.

What Gets Cached?

CDNs primarily cache static assets — content that doesn't change between requests:

  • Images: JPGs, PNGs, WebP, SVGs — usually the largest portion of a page's weight
  • JavaScript files: Application bundles, third-party scripts
  • CSS stylesheets: Your design and layout files
  • Fonts: Web fonts that would otherwise be loaded from Google Fonts or similar
  • HTML pages: For static sites and SSR content with appropriate cache headers
  • Videos: Streaming video content served from the edge

Dynamic content — personalized pages, API responses with user-specific data — is typically not cached. Modern CDNs can cache API responses with short TTLs (time-to-live) for frequently requested data that doesn't change often, like product listings or blog posts.

Benefits Beyond Speed

DDoS Protection

CDNs absorb massive amounts of traffic. A distributed denial-of-service attack that would overwhelm your single server is spread across the CDN's entire network, often neutralized before it reaches your origin. Cloudflare, for example, regularly absorbs attacks measuring hundreds of Gbps.

Reduced Origin Server Load

With a CDN serving 80-95% of requests from cache, your origin server handles a fraction of the traffic. This means you can run smaller (cheaper) servers and still handle traffic spikes gracefully. When a post goes viral, the CDN absorbs the surge.

Automatic HTTPS and HTTP/2

Most CDNs automatically provision SSL certificates and serve content over HTTPS and HTTP/2. HTTP/2 enables multiplexing — loading multiple files simultaneously over a single connection — which dramatically reduces page load times.

Global Availability

If your origin server goes down, a CDN can continue serving cached content to users. This provides a degree of resilience and can keep your site accessible during maintenance or outages.

Cache Headers and Cache Control

CDNs respect HTTP cache headers to know how long to store content. Setting appropriate cache headers is crucial to CDN effectiveness:

  • Cache-Control: max-age=31536000, immutable: Cache this file for one year. Use for versioned assets like hashed JS bundles.
  • Cache-Control: no-cache: Check with the origin on every request (but can still use cached version if unchanged).
  • Cache-Control: no-store: Never cache this — for private, user-specific data.
  • ETag / Last-Modified: Conditional headers that allow the CDN to verify if content has changed without re-downloading it.
Fingerprinting for Long Cache TTLs

Modern build tools (Vite, webpack, Next.js) automatically add content hashes to filenames: app.a3f2c891.js. Because the filename changes whenever the content changes, you can safely set cache TTLs of one year. Users always get the latest version because the filename is different, but returning visitors load the cached version instantly.

Popular CDN Providers

  • Cloudflare: Free tier available, excellent DDoS protection, easy setup. The most popular choice for websites of all sizes. Also offers Workers for edge computing.
  • AWS CloudFront: Tightly integrated with the AWS ecosystem. Good choice if you're already on AWS. Pay-per-request pricing.
  • Fastly: Premium CDN favored by large tech companies. Highly configurable with VCL (Varnish Configuration Language).
  • Bunny.net: Affordable pricing with excellent performance. Great for video streaming and high-bandwidth use cases.
  • Vercel Edge Network: If you deploy on Vercel, their CDN is built-in. Excellent for Next.js applications.

Do You Need a CDN?

Almost certainly yes. Even for small sites, the benefits outweigh the cost — especially since Cloudflare offers a generous free tier. Consider a CDN if:

  • Your users are geographically distributed (any users outside your server's region)
  • You serve any significant amount of images, video, or static files
  • You want protection against traffic spikes and DDoS
  • Page speed is important (it always is, for both UX and SEO)

The only scenario where a CDN might not help is a highly dynamic, fully personalized app with no cacheable content and a regionally concentrated user base — and even then, the DDoS protection and TLS termination benefits remain valuable.

Conclusion

A CDN is one of the highest-leverage infrastructure improvements you can make. By serving content from the edge — close to your users — you reduce latency, protect your origin server, absorb traffic spikes, and improve reliability. For most websites, adding Cloudflare's free CDN takes minutes and delivers immediate, measurable improvements in page load time for users around the world.