How CDNs Work
debt(d7/e3/b5/t5)
Closest to 'only careful code review or runtime testing' (d7). Tools listed are lighthouse, curl, and webpagetest — these are performance/audit tools that can surface missing CDN usage or bad Cache-Control headers, but they require deliberate manual auditing runs rather than catching issues automatically during development. The absence of CDN or misconfigured headers won't fail a build or lint step; it silently degrades performance in production until someone runs a performance audit.
Closest to 'simple parameterised fix' (e3). The quick_fix describes serving static assets through a CDN with immutable cache headers, which is a meaningful but bounded change: updating asset URLs/configuration to point through a CDN and adding proper Cache-Control headers. It's more than a single-line patch but doesn't require cross-cutting refactors — it's localised to asset serving configuration and potentially a few HTTP response headers.
Closest to 'persistent productivity tax' (b5). The choice applies to the web context broadly — decisions about Cache-Control headers, CDN configuration, and what to cache affect many aspects of deployment, content updates (cache invalidation strategies), API design (cacheability), and cookie handling. It's not purely localised to one component but doesn't fully define system shape; however, it persistently influences how developers think about URL design, cache busting, and response headers across the codebase.
Closest to 'notable trap — a documented gotcha most devs eventually learn' (t5). The misconception field directly states it: developers believe CDNs only cache static files, when in reality any HTTP response with correct Cache-Control headers is CDN-cacheable — including JSON API responses and PHP-rendered HTML. The common_mistakes also highlight serious traps like caching Set-Cookie responses (serves another user's cookie) and Vary: * disabling all caching. These are well-documented gotchas that are non-obvious but eventually learned.
Also Known As
TL;DR
Explanation
Anycast routing: multiple edge servers share the same IP address; BGP routes requests to the geographically closest PoP. Cache miss: the edge fetches from origin and caches the response. Cache key: URL + Vary headers. Benefits: latency reduction, throughput offload from origin, reliability when origin is down, DDoS absorption. PHP sends Cache-Control: public, s-maxage=N to enable CDN caching. Dynamic API responses with correct headers are CDN-cacheable too.
Common Misconception
Why It Matters
Common Mistakes
- No Cache-Control headers — CDN cannot cache
- Caching Set-Cookie responses — serves another user's cookie
- Vary: * disables all caching
- Same URL different content without Vary header
Code Examples
// No cache headers — CDN pass-through:
public function products(): JsonResponse {
return response()->json(Product::all());
// Every request hits PHP and database — CDN provides no benefit
}
// CDN-cacheable response:
public function products(): JsonResponse {
$etag = md5($this->productService->getLastModified());
return response()
->json($this->productService->all())
->withHeaders([
'Cache-Control' => 'public, s-maxage=300, stale-while-revalidate=60',
'ETag' => $etag,
'Vary' => 'Accept-Encoding',
]);
// CDN serves for 5 minutes without touching PHP
}