Skip to main content
>_ supraj.dev
TOPIC NETWORKING
CDN serving content from a server near your user
IN 10 SECONDS

A Content Delivery Network (CDN) caches static assets — images, JS, CSS, videos — at edge locations around the world. When a user in Tokyo requests your site, the CDN serves from a Tokyo edge node instead of fetching from your origin server in Virginia. This cuts latency dramatically and offloads traffic from your origin.

GOTCHA Caching dynamic content (HTML, APIs) in a CDN can serve stale data. Use `Cache-Control: no-cache` or `s-maxage=0` for dynamic pages. For cache invalidation, most CDNs support purge API — but it's not instant (propagation can take minutes).
HOW A CDN SERVES A CACHED FILE
01 User requests `https://cdn.example.com/logo.webp` from their browser.
02 DNS resolves the CDN hostname to the nearest edge server (e.g., Tokyo).
03 Edge server checks its local cache. If the file is there and not expired, it serves it immediately (cache hit).
04 Origin fetch on a cache miss, the edge fetches from your origin server, caches it, and serves it to the user.
05 Cache headers `Cache-Control: max-age=31536000` tells the edge and browser how long to keep the file.
POKE IT YOURSELF
curl -sI https://cdn.example.com/file.js — check cache headers on a CDN asset
aws cloudfront create-invalidation --distribution-id DIST_ID --paths "/*" — purge entire CloudFront cache