Cache-Control for Security (Cache-Control Security)
Why You Should Care About Cache-Control Security
By default, browsers and proxies may cache HTTP responses to improve performance. For pages containing sensitive data (account settings, financial information, personal details), cached copies create a security risk. On shared computers, the next user could use the browser's back button to view cached pages from the previous user's session.
For authenticated pages and API responses containing personal data, set Cache-Control: no-store to prevent any caching. The no-store directive is stronger than no-cache (which allows caching but requires revalidation). For pages behind authentication, no-store is the appropriate choice.
Static assets like images, CSS, and JavaScript can safely use long cache times (max-age=31536000, immutable for versioned assets). The key is distinguishing between public assets (cacheable) and personal data responses (not cacheable). Getting this wrong in either direction hurts either security or performance.
How to Verify
A security audit checks Cache-Control headers on your responses. Verify that authenticated API responses and pages with personal data use no-store. Verify that public static assets use appropriate caching for performance.