On this page
  1. How does a CDN work?
  2. When does a CDN actually matter?
  3. What does a CDN cost?
  4. Where AI coding assistants get this wrong
  5. Checklist
  6. FAQ
    1. Is a CDN the same as web hosting?
    2. Can a CDN make an API faster?
  7. Related topics
  8. Sources
concept

What Is a CDN and Do You Need One?

A CDN caches your site on servers near your visitors, making it load faster worldwide. When it matters, when it's overkill, and what it costs.

Quick answer

  • A CDN (content delivery network) is a network of servers that cache your content closer to visitors.
  • It cuts load times for distant users and absorbs traffic spikes that would overload your origin server.
  • For a static site or small API, a free CDN tier like Cloudflare is usually all you need.

How does a CDN work?

When someone requests your domain, the CDN’s DNS routes them to the nearest edge server, which serves a cached copy instead of hitting your origin server. Cached content — HTML, images, CSS, JS — is served from memory near the visitor, so a user in Sydney loading a site hosted in Frankfurt doesn’t wait for a round trip across the planet. Only cache misses go back to your origin.

When does a CDN actually matter?

It matters most when your visitors are geographically spread out, your site is heavy on static assets, or you get traffic spikes. For a small site whose users are in the same region as the server, a CDN adds little: the origin already responds quickly. It also adds security features in most cases (DDoS filtering, bot protection), which is a separate reason to use one even when speed doesn’t demand it.

What does a CDN cost?

Cloudflare’s free tier covers a personal or small business site completely: CDN, TLS, and DDoS protection. Paid tiers add more caching control, image optimization, and WAF rules. You pay nothing for a hobby project, and you should only pay when you need features the free tier lacks.

Where this bites vibecoders

Vibecoders usually learn about CDNs the hard way: a demo goes viral, or a friend in another country reports the site is painfully slow. Worse, an AI assistant may suggest a complex self-hosted caching setup when pointing the domain at Cloudflare’s free tier would fix latency, TLS, and DDoS protection in ten minutes. If your site is static, the CDN is the easy win.

Where AI coding assistants get this wrong

  • Recommending elaborate server-side caching when a CDN in front of the origin is the simpler fix.
  • Writing cache headers that tell the CDN to cache HTML that contains user-specific data.
  • Forgetting to purge the cache after deploys, so visitors see stale pages.
  • Disabling the CDN entirely because one dynamic route misbehaved, instead of excluding just that route.

Checklist

  • Put a CDN in front of any site with geographically spread visitors.
  • Serve static assets with long cache lifetimes and cache-busted filenames.
  • Never cache responses that contain personalized data.
  • Purge the cache after every deploy, or rely on deploy hooks that do it for you.

FAQ

Is a CDN the same as web hosting?

No. A CDN caches and delivers copies of your content; hosting runs the origin server that creates it. You can use a CDN in front of any host, including Netlify, Vercel, or your own VPS.

Can a CDN make an API faster?

Only for responses that are cacheable — public data, images, or static JSON. Dynamic, per-user API responses can’t be cached, though the CDN still provides TLS and DDoS protection for them.

Sources

Share: