CachingResponse & Request

Cache-Control

Specifies browser and CDN caching directives for requests and responses, dramatically accelerating load speeds or preventing cache leakage.

Recommended Production Value
Essential (A+)
public, max-age=31536000, immutable (Static Assets) OR no-store, max-age=0 (Dynamic APIs)

Production Server Implementation

NGINX Configuration Snippet
expires 1y; add_header Cache-Control "public, immutable";

Directives & Syntax Breakdown

no-store

Forbids browsers and CDNs from storing any response data on disk or memory (essential for private user data).

max-age=<seconds>

Maximum lifetime in seconds that a cached resource is considered fresh.

immutable

Indicates the response body will never change over time, bypassing conditional validation requests.

stale-while-revalidate=<seconds>

Allows serving stale cached data instantly while fetching an updated copy in the background.

Common Security Hazards & Pitfalls

  • β€’Do NOT use "immutable" on assets without cache-busting hashes (like main.css instead of main.a1b2c3.css).
  • β€’Using "no-cache" does NOT mean do not cache; it means revalidate with the server before using.
Frequently Asked Questions

Cache-Control - Questions & Answers

Common implementation questions, browser enforcement rules, and debugging.

"public, max-age=31536000, immutable" provides maximum performance because modern bundlers give changed files unique hashes.