Course contentsShow
← Web Development
Lesson 2142 of 2,98239. Network PerformanceFree lesson

Cache-Control Directives

Learning max-age, no-cache, no-store, private, public, and must-revalidate directives.

Cache-Control Directives

You'll learn how to fine-tune HTTP caching behavior using specific Cache-Control header directives to control when, where, and how long resources are stored.

What Are Cache-Control Directives?

The Cache-Control header isn't just an on/off switch—it's a collection of directives (instructions) that tell browsers and intermediary caches exactly how to handle your resources. Think of it like a detailed instruction manual rather than a simple "cache this" command.

Core Directives Explained

max-age sets how many seconds a resource is fresh:

Cache-Control: max-age=3600

This means "cache for 1 hour." After that, the browser must revalidate.

no-cache (confusingly named!) doesn't mean "don't cache"—it means "always check with the server before using the cached version." The server can respond with 304 Not Modified if unchanged.

no-store is the nuclear option: don't cache at all. Use for sensitive data like bank transactions.

private means only the user's browser can cache this (not shared CDNs or proxies). Perfect for personalized content.

public allows any cache (CDNs, proxies, browsers) to store the resource. Great for static assets everyone shares.

must-revalidate tells caches they cannot serve stale content under any circumstances—they must check with the origin server once max-age expires, even if offline.

Combining Directives

You can stack these:

Cache-Control: public, max-age=31536000, must-revalidate

Key Takeaway: Cache-Control directives give you granular control over caching behavior—use max-age for freshness duration, no-store for sensitive data, private/public for cache location, and no-cache/must-revalidate for validation requirements.