Browser caching can reduce repeat downloads and improve navigation speed. A correct policy depends on whether a resource is public, personalized, versioned and likely to change. Cache headers should be designed around the content lifecycle rather than applied globally.
Cache versioned assets
Files whose URLs change when their content changes can use long-lived freshness directives. A fingerprinted filename allows a new release to publish a new URL while existing visitors safely reuse the old asset until the page references the new one.
Use validators when content is not fingerprinted
ETags and Last-Modified allow a browser to ask whether a resource has changed. The server can respond with a not-modified status instead of transferring the full body. Ensure validators are stable enough for the deployment model and do not expose sensitive internal metadata.
Protect private responses
Personalized pages and account data should not be stored in shared caches. Use appropriate private or no-store directives depending on sensitivity and application behavior. Be especially careful when a reverse proxy or CDN sits between users and the origin.
Test real response headers
Inspect headers for HTML, CSS, JavaScript, images, downloads and API responses. Check behavior after deployment and when users sign out. A cache policy that is correct for public assets may be unsafe for authenticated responses.
Checklist
- Use long-lived caching for fingerprinted public assets.
- Use validators for suitable unversioned resources.
- Keep personalized responses out of shared caches.
- Review CDN and browser cache behavior together.
- Test headers across content types and authentication states.