categories.performance Intermediate
CDN Strategy and Static Asset Optimization
Explain how CDNs work and how to use them effectively.
What Is a CDN
A Content Delivery Network distributes static assets to edge servers worldwide, so users fetch resources from the nearest node, reducing latency.
How It Works
- User requests a resource.
- DNS resolves to the nearest CDN edge server.
- Edge server returns cached response (Cache Hit) if available.
- Otherwise, pulls from origin (Origin Pull) and caches the result.
Cache Control
- Static assets (hashed JS/CSS): Set long TTL (e.g., 1 year); rely on URL changes for invalidation.
- Dynamic content (HTML): Set short TTL or no-cache.
CDN Offload Strategy
- Static assets (images, JS, CSS, fonts): Route all through CDN.
- API responses: Use Stale-While-Revalidate for some.
- User-generated content: Upload directly to CDN origin (e.g., S3) to bypass the app server.
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
