The Ideal Cache Citizens
static content = bytes that don't change per user or per request:
JS/CSS bundles, images, fonts, video segments,
downloads, documents, generated reports (once written)
properties that make them perfect for edge caching:
- identical for ALL users → maximum key sharing
- versioned by filename → no invalidation needed
- high volume + high reuse → hit rates 95-99.9%
The Immutable Pattern End-to-End
build pipeline:
app.js → app.d41d8cd9.js (content hash in name)
headers served (via CDN):
/app.d41d8cd9.js
Cache-Control: public, max-age=31536000, immutable
/index.html
Cache-Control: no-cache ← always revalidate; points to new hashes
consequences:
- deploys: new hashes appear; old cached files remain valid
mid-session users finish on the old bundle seamlessly
- ZERO purge machinery needed — filenames ARE versions
- edge hit rate → ~100%; origin sees ~one fetch per file per region EVER
Image and Media Handling
variants multiply content: same photo × sizes × formats:
photo.jpg → photo_400.webp, photo_800.webp, photo_orig.jpg
key design: encode variant in PATH (cacheable), never query hacks:
✓ /img/800/photo_abc.webp clean distinct keys
✗ /img/photo?w=800&fmt=webp query params need explicit key config
on-the-fly transformation at edge (many CDNs offer it):
first request for a size → generate+cache; rest are hits.
origin stores ONE original.
Video Segments
HLS/DASH slice video into 2-10s segments:
/video/123/seg_047.ts
- identical for every viewer → shared aggressively
- popularity follows the SAME power law as pages
- live streams: short TTLs on the sliding window;
VOD: immutable forever
origin math with shielding: one segment upload →
~1 fetch per region total. this is why streaming works at scale.
Cache-Key Hygiene for Static
audit what enters your keys:
- strip analytics junk (_, fbclid, utm_*) via key-normalization config
- case-normalize paths
- Vary header discipline: Vary: Accept-Encoding only where real;
accidental Vary: User-Agent fragments caches into thousands
of near-duplicate entries (classic mobile-era wound)
Numbers to Internalize
typical static-offload outcomes:
asset requests hitting origin: <1%
latency p50 far-region: ~150ms → ~15ms
egress cost: shifted to cheaper CDN pricing
deploy propagation: instant globally (new names)
static delivery is SOLVED engineering — the interview question
is whether you reach for the whole pattern reflexively.
Interview Framing
“Serve product images globally” scored answer: CDN edges + immutable/versioned URLs, path-encoded variants, key normalization against junk params, shield mention, and the deploy story (hashes make purges unnecessary). Bonus depth: edge-transform for responsive sizes keeping origin storage minimal.
Premium Content
Unlock Static Content Delivery and all premium lessons with a subscription.
All premium lessons
Ad-free experience
Priority support
From ₹199.99/year — See plans