Intermediate Performance
Caching Strategies
Browser cache, CDNs, service workers, and cache invalidation.
Caching for Speed
Effective caching dramatically reduces load times for returning visitors.
Browser Caching
# Immutable assets (hash in filename)
Cache-Control: public, max-age=31536000, immutable
# Dynamic content
Cache-Control: private, no-cache
# Never cache
Cache-Control: no-storeCaching Layers
- Browser Cache: Local storage on device
- CDN Cache: Edge servers worldwide
- Application Cache: Redis, in-memory
- Database Cache: Query cache, indexes
Service Workers
// Cache-first strategy
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request)
.then(cached => cached || fetch(event.request))
);
});CDN Best Practices
- Cache static assets at the edge
- Use content-based hash in filenames
- Set appropriate cache headers
- Purge cache on deployments