Cache-Control is an HTTP header controlling browser and CDN caching. For immutable assets (JS/CSS/images with hash) — public, max-age=31536000, immutable (1 year). For HTML — public, max-age=60, stale-while-revalidate=86400. For APIs — no-store. Correct config speeds up repeat visits by 30-80%.
Below: step-by-step, working examples, common pitfalls, FAQ.
Free online tool — HTTP header checker: instant results, no signup.
Cache-Control: public, max-age=31536000, immutableCache-Control: public, max-age=60, s-maxage=600Cache-Control: no-store (personal data) or private, max-age=0, must-revalidate| Scenario | Config / Record |
|---|---|
| nginx: static with hash (1 year) | location ~* \.(js|css|png|jpg|woff2)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
} |
| nginx: HTML (short cache) | location / {
add_header Cache-Control "public, max-age=60, s-maxage=600";
} |
| Apache: .htaccess static | <FilesMatch "\.(js|css|png|jpg|woff2)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch> |
| API (no-cache) | Cache-Control: no-store, no-cache, must-revalidate |
| CDN-aware (CDN caches, browser does not) | Cache-Control: public, max-age=0, s-maxage=86400 |
Cache-Control: no-cache ≠ "don't cache". It means "always revalidate". Use no-storeTo set Cache-Control headers effectively, use the HTTP response header to dictate how, and for how long, browsers cache your web resources. For example, to cache static assets for one week, apply the header Cache-Control: public, max-age=604800. This guide provides comprehensive steps for configuring Cache-Control headers across various platforms, including Nginx, Apache, and Node.js.
The Cache-Control HTTP header is crucial for managing the caching behavior of web resources. This header can significantly impact the performance and efficiency of your web applications. In this section, we will explore the various directives available in the Cache-Control header, their implications, and best practices for implementation.
max-age=3600 means the resource is fresh for one hour.Understanding these directives allows you to tailor your caching strategy according to your website's needs. For example, if you have static assets that change infrequently, you may want to set a longer max-age value to reduce server load and improve load times for users.
When setting Cache-Control headers, consider the following best practices:
style.v1.css) to ensure users receive the latest version after updates.In the next section, we will provide practical examples for setting Cache-Control headers on various web servers, including Nginx and Apache. These examples will help you implement the directives discussed here effectively.
<code>max-age</code> — TTL for private caches (browser). <code>s-maxage</code> — TTL for shared caches (CDN, proxy). If both are set — each cache uses its own.
A Cache-Control directive: "this resource will never change". The browser skips revalidation (If-None-Match) even on reload. Important for hash-based assets.
Yes. Cache-Control says "cache is valid for N seconds". ETag is used at expiry for 304 Not Modified (conditional requests). They complement each other.
<a href="/en/check">Enterno HTTP Checker</a> → enter URL → Cache section shows Cache-Control, ETag, Age, max-age.
Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.