CACHE WITH INTENT

Cache-Control headers: how to cache HTML and fingerprinted assets correctly, and how to check your caching headers

Without Cache-Control, ETag or Last-Modified, browsers and CDNs cannot tell whether a stored copy is still good, so repeat visits download everything again. This guide explains how HTTP caching decides between fresh, stale and revalidated, the difference between no-cache and no-store, and why HTML and fingerprinted assets need opposite policies. It includes configurations for nginx, Apache, Node and CDNs, plus the commands to verify the result.

Concept illustration of an ivory ceramic apothecary shelf on a charcoal background: rows of translucent glass jars sealed with copper caps hold mint-glowing crystals, while one open jar at the front sits beside a small copper balance comparing two identical crystals.
Concept illustration

Every time a browser loads one of your pages, it has to decide whether it can reuse something it already downloaded. The answer comes from the server, in three response headers: Cache-Control, which states how long a response may be reused and by whom; ETag and Last-Modified, which let the browser ask cheaply whether its copy is still current. When none of them is present, browsers and CDNs have to guess, and the safe guess is usually to download the whole response again. Sitelemetry reports that situation as delivery.caching.missing.

Old performance tools called the fix “leverage browser caching”. Current practice is more precise: HTML is revalidated on every visit so content changes show up immediately, while fingerprinted assets, such as app.3f9a1c2b.js, are cached for a year and marked immutable. This guide explains the mechanism, the directives that people most often confuse, configurations for nginx, Apache, Node and CDNs, and the commands to verify the result. All examples use example.com.

Caching is a performance topic, but it is also a correctness topic. A wrong policy can keep visitors on an old version of a page for days, or let a shared cache store a page meant for a single signed-in user. The goal is not the maximum amount of caching. It is the right policy for each type of response.

Scope of this guide

This guide covers HTTP caching headers that can be observed from outside. Sitelemetry reads one home page response and checks whether caching headers exist, not whether the policy suits your content. It does not test your CDN rules or every asset, and it is not a pentest.

1. What the delivery.caching.missing finding means

The finding is raised when the home page response of the origin you scan looks like HTML, or carries no Content-Type at all, and has none of these three headers: Cache-Control, ETag or Last-Modified. It is rated low severity. Your site still works, but every cache between the server and the visitor is working with no instructions.

In practice that has two consequences:

  • No freshness information. A cache does not know how long the copy stays valid. RFC 9111 allows caches to apply their own heuristics in that case, so behaviour varies between browsers and CDNs, and the result is hard to predict.
  • No validator. Without an ETag or Last-Modified, the browser cannot send a conditional request, and the server cannot answer 304 Not Modified. Every check for changes downloads the full body again.

The usual causes are easy to recognise. Static file servers such as nginx and Apache normally send ETag and Last-Modified for files on disk by default. HTML generated by an application, such as a PHP template, a Node or Python handler or a serverless function, often goes out with no caching headers unless someone adds them. A reverse proxy or a security layer that removes upstream headers can produce the same result.

2. How HTTP caching works: freshness and validation

HTTP caching rests on two ideas, both defined in RFC 9111 and RFC 9110.

Freshness. A stored response is fresh while its age is below its freshness lifetime, usually set with Cache-Control: max-age=N in seconds, or with the older Expires date. While a response is fresh, the cache can reuse it without contacting the server at all. This is the fastest outcome, because no request is sent.

Validation. Once the response is stale, or if the policy requires a check every time, the cache sends a conditional request. It sends If-None-Match with the stored ETag, or If-Modified-Since with the stored Last-Modified date. If nothing changed, the server replies 304 Not Modified with headers only, and the cache reuses its copy.

GET / HTTP/1.1
Host: example.com

HTTP/1.1 200 OK
Cache-Control: no-cache
ETag: "a1b2c3"
(full HTML body)

GET / HTTP/1.1
Host: example.com
If-None-Match: "a1b2c3"

HTTP/1.1 304 Not Modified
ETag: "a1b2c3"
(no body)

Caches come in two kinds. A private cache is the visitor’s browser and serves a single user. A shared cache, such as a CDN or a corporate proxy, serves many users from one stored copy. Some directives apply only to shared caches, which matters as soon as you put a CDN in front of your origin.

When a response has no explicit freshness information, RFC 9111 (section 4.2.2) lets a cache compute a heuristic lifetime. If Last-Modified is present, the RFC suggests a fraction of the time since that date and mentions 10% as a typical setting. This explains why a page with only Last-Modified can stay cached for hours in one browser and be fetched again every time in another. Explicit directives remove the guesswork.

3. The directives: no-cache versus no-store, and the rest

Most caching mistakes come from directive names that read as if they meant something else. The MDN Cache-Control reference lists all of them. These are the ones you will use:

DirectiveWhat it actually meansTypical use
max-age=NThe response is fresh for N seconds and can be reused without a requestAssets, and short-lived public HTML
s-maxage=NSame as max-age, but only for shared caches; overrides max-age thereA different lifetime at the CDN than in the browser
no-cacheThe response may be stored, but must be revalidated with the server before every reuseHTML pages that should always be current
no-storeNo cache may store the response at allPages and API responses with personal or sensitive data
privateOnly the browser may store it; shared caches must notPersonalised pages for signed-in users
publicShared caches may store it, even in cases where they normally would notStatic assets
must-revalidateOnce stale, the response must not be reused without a successful revalidationContent where serving a stale copy would be wrong
immutableThe response will not change while fresh, so supporting browsers skip revalidation, even on reload (RFC 8246)Fingerprinted assets only
stale-while-revalidate=NAfter expiry, a stale copy may be served for N more seconds while the cache revalidates in the backgroundPublic HTML or API responses where a few seconds of staleness is acceptable

The pair that causes most confusion is no-cache and no-store. no-cache does not mean “do not cache”. It means “check with me first”. Combined with an ETag, it gives you up-to-date pages while unchanged pages still return a cheap 304. no-store is the one that forbids storage. It also rules out 304 responses, because the browser has no copy to validate, so use it only where storage is actually a problem.

Two legacy headers still show up in older configurations. Expires sets an absolute date, and a max-age directive takes precedence over it when both are present. Pragma: no-cache is an HTTP/1.0 request header and has no defined meaning in responses, so do not rely on it to control caching.

4. Two opposite policies: HTML versus fingerprinted assets

The best practice that web.dev describes splits responses by one question: can the content at this URL ever change?

  • Fingerprinted assets have a content hash in their filename, for example /assets/app.3f9a1c2b.js. When the code changes, the build tool produces a new filename. The content at a given URL never changes, so it can be cached for a year.
  • HTML lives at stable URLs such as / or /pricing. It is also the pointer that tells the browser which asset filenames to load. If HTML is cached for a long time, visitors keep loading old asset names after a deploy, which can mean an outdated page or a broken one.
Response typeRecommended headerWhy
Fingerprinted JS, CSS, fonts, imagespublic, max-age=31536000, immutableOne year, and no revalidation; a change means a new URL
Public HTML pagesno-cache plus an ETagAlways current; unchanged pages cost a 304
Public HTML where brief staleness is acceptablemax-age=300 plus an ETagFive minutes without requests, then revalidation
Unversioned files such as /favicon.ico or /logo.pngmax-age=86400 plus a validatorA moderate lifetime, because the URL cannot change when the file does
Signed-in, personalised HTMLprivate, no-cacheBrowser only, never a shared cache, always revalidated
Account, payment or personal-data responsesno-storeNothing kept on disk or at the edge

The lifetimes in this table are starting points, not rules. Choose the HTML lifetime based on how quickly corrections must reach visitors. For a news site or a shop with live stock levels, that means no-cache. For a brochure site updated monthly, a few minutes is harmless.

5. max-age, immutable and cache busting

max-age=31536000 is one year in seconds. It is the conventional value for versioned assets and the one-year example used in Lighthouse’s cache-policy documentation. Shorter lifetimes on hashed files only cause unnecessary revalidation.

immutable, defined in RFC 8246, addresses the reload case. When a visitor presses reload, browsers traditionally revalidate the subresources on the page, even fresh ones, which produces a burst of requests that all end in 304. With immutable, a supporting browser skips those requests for as long as the response is fresh. Browsers that do not understand the directive simply ignore it, so including it is safe.

Cache busting only works if the URL changes with the content:

  • Filename hashes are the most reliable method. Vite, webpack, esbuild-based tools and most framework build pipelines produce them by default for bundled code.
  • Query strings such as style.css?v=42 work in browsers, but some CDN setups are configured to ignore query strings in the cache key. Check yours before you rely on this method.
  • Files outside the build, such as uploaded images or a CMS theme file at a fixed path, are not versioned. Never give them a one-year lifetime.

A long lifetime cannot be recalled. If an unversioned URL goes out with max-age=31536000, immutable, visitors who received it keep that copy until it expires or they clear their cache. Purging the CDN does not reach browser caches. The only reliable fix is to publish the content at a new URL and update the references. Apply long lifetimes by path or filename pattern, not to everything.

6. ETag and Last-Modified: validators done right

Validators are what make no-cache and expired responses cheap. RFC 9110 defines two kinds:

  • Last-Modified is a date with one-second precision. It is simple to produce for files, but a dynamic page needs the application to know when its underlying content last changed.
  • ETag is an opaque identifier for one version of the response, for example "a1b2c3". A W/ prefix marks a weak validator, which means “semantically equivalent” rather than byte-identical. When both validators are present, servers evaluate If-None-Match first.

Common pitfalls:

  • Different ETags on different servers. If each node behind a load balancer derives the ETag from local file metadata, the same file can get a different ETag on each node, and revalidation keeps failing. Derive ETags from content, or make sure every node produces the same value for the same content.
  • Compression changes ETags. nginx turns a strong ETag into a weak one when it compresses a response on the fly. This is expected and still allows 304 responses. Just do not compare raw ETag strings across compressed and uncompressed fetches when you debug.
  • Generated pages without validators. Express adds weak ETags to bodies sent with res.send by default. Many other frameworks need a middleware or an explicit setting. Without a validator, no-cache still forces a request every time, but the server always sends the full body.
  • Validators do nothing with no-store. If nothing is stored, there is nothing to validate.

7. Configuring caching on common stacks

nginx

Set the header per location, with always so that it also applies to error responses. nginx sends ETag and Last-Modified for static files by default. Note that an add_header inside a location replaces every add_header inherited from the server block, including your security headers, so repeat them or move them to an included file (nginx headers module).

server {
    listen 443 ssl;
    server_name example.com;
    root /var/www/example;

    location /assets/ {
        add_header Cache-Control "public, max-age=31536000, immutable" always;
    }

    location / {
        add_header Cache-Control "no-cache" always;
    }
}

Apache

With mod_headers enabled, match versioned files by pattern and send HTML through revalidation:

<IfModule mod_headers.c>
  <FilesMatch "\.[0-9a-f]{8,}\.(js|css|woff2|svg|png|webp)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.html$">
    Header set Cache-Control "no-cache"
  </FilesMatch>
</IfModule>

When HTML is produced by a script, such as index.php behind a rewrite, a FilesMatch on .html never matches it. Set the header in the application instead. PHP’s session handling, with its default session.cache_limiter setting, already sends no-store style headers on pages that start a session. Check that this matches what you intend.

Node.js with Express

app.use('/assets', express.static('dist/assets', {
  maxAge: '1y',
  immutable: true
}));

app.get('/', (req, res) => {
  res.set('Cache-Control', 'no-cache');
  res.send(renderHome()); // weak ETag added by default
});

Frameworks and hosting platforms

Many frameworks and static hosts already send long-lived headers for their hashed build output and short or revalidating headers for HTML. Server-rendered routes, API handlers and anything you add outside the build pipeline often fall back to sending no caching headers. Check the actual response with the commands in section 9 instead of assuming the platform default covers it.

8. CDNs and shared caches

A CDN adds a second cache layer with its own defaults, and that layer is where most surprises happen.

  • Default rules. Many CDNs cache common static file types out of the box but do not cache HTML unless you configure them to. Some override origin lifetimes with an edge TTL from their dashboard. Read your provider’s documentation on whether origin Cache-Control is respected, ignored or overridden.
  • Separate edge and browser lifetimes. s-maxage applies only to shared caches. RFC 9213 also defines CDN-Cache-Control, which targets CDNs specifically and is supported by several providers. A common pattern is HTML with Cache-Control: no-cache for browsers and a short CDN lifetime, combined with a purge on deploy.
  • Personalised responses. Mark them private or no-store. Many CDNs do not cache responses that set cookies by default, but relying on that default is fragile. A misconfigured rule that caches a signed-in page at the edge can show one visitor’s page to another.
  • Vary. Vary: Accept-Encoding keeps compressed and uncompressed copies apart, and servers that compress usually add it. Vary: Cookie or Vary: User-Agent splits the cache into so many variants that the hit rate collapses.
  • Purging. With fingerprinted assets, a deploy needs no asset purge because the URLs are new. Purge the HTML and any unversioned files. Remember that a purge clears the edge, not visitors’ browsers.

To see what the CDN did with a request, look at the Age header, which shows seconds spent in cache, and at the cache status header. Some providers send the standard Cache-Status header from RFC 9211. Others use vendor names such as cf-cache-status or X-Cache.

9. How to check your headers and verify the fix

Start with the HTML and one versioned asset, using GET requests. A HEAD request is quicker but can be handled by a different code path on some setups.

curl -sS --compressed -D - -o /dev/null https://example.com/
curl -sS --compressed -D - -o /dev/null https://example.com/assets/app.3f9a1c2b.js

The first response should show cache-control: no-cache, or your chosen short lifetime, plus an etag or last-modified. The second should show public, max-age=31536000, immutable. On Windows, call curl.exe and use -o NUL.

Then confirm that revalidation works. Copy the ETag from the first response, including its quotes and any W/ prefix, and send it back:

curl -sS --compressed -o /dev/null -w "%{http_code}\n" \
  -H 'If-None-Match: "a1b2c3"' https://example.com/

The expected result is 304. If you get 200 every time, the ETag changes between requests (look for timestamps, nonces or CSRF tokens rendered into the page), or the application does not handle conditional requests.

In the browser, open DevTools, go to the Network panel, make sure “Disable cache” is unchecked, and load the page twice:

  • Assets should show (memory cache) or (disk cache) in the Size column, with no network request.
  • The document should show 304 when nothing changed and 200 with new content after a deploy.
  • Select a request to compare its response headers with what you configured. CDNs and plugins sometimes rewrite them.

Finally, run Lighthouse or PageSpeed Insights. Its “Use efficient cache lifetimes” insight (called “Serve static assets with an efficient cache policy” before Lighthouse 13) lists static resources with short or missing lifetimes, which helps you find assets the configuration patterns missed. Repeat these checks after CDN rule changes, server migrations and framework upgrades, because those are the moments when headers silently change.

10. What Sitelemetry checks for caching

The caching check is part of Sitelemetry’s transport and delivery module. This module also reports compression (see the gzip and Brotli guide) and identifies a CDN from response headers. The check is passive: it sends one GET request to the home page of the origin you enter, following redirects, and reads the response headers. It does not request your assets or test conditional requests. If that response is not a 2xx page or is a bot challenge, the module reports that the probe could not complete and gives no caching verdict. It applies the following logic:

What the response containsResultSeverity
A Cache-Control header with any valuedelivery.caching.ok, “Cache policy present”, with the observed value and a note if an ETag or Last-Modified is also presentInfo (unscored observation)
HTML or no Content-Type, with no Cache-Control, ETag or Last-Modifieddelivery.caching.missing, “No caching directives”Low
No Cache-Control, but an ETag or Last-ModifiedNo caching findingNone
No caching headers on a non-HTML Content-TypeNo caching findingNone

This is a presence check. It does not judge whether the value suits your content: no-store on a public page and a one-year lifetime on unversioned HTML both count as a policy being present. It does not inspect static assets, CDN rules or edge lifetimes. Use the curl and DevTools steps above for those. The remediation it suggests matches this guide: long max-age with immutable for static assets, and a validator-based policy for dynamic content.

The check is part of the free Launch Readiness Snapshot, which runs 8 passive checks (DNS, email DNS, domain registration, TLS, security headers, HTTPS posture, technology fingerprint and delivery) on one public domain without signup or ownership verification. In account plans, the transport and delivery module is included in Professional ($149/month) and Enterprise ($249/month). Because account security audits also run checks that require ownership verification, an account audit needs a verified target; the snapshot does not. It is not included in the Free plan, but a Free account can run one security audit at Professional depth, which includes this check, with a security audit credit and a verified target; every Free account starts with one audit credit per audit area. Sitelemetry is an automated audit tool, not a penetration test or a certification. For the broader performance picture, read the website performance audit guide. For the other response headers that often sit next to Cache-Control, see the TLS and security headers guide. Plan details are on the pricing page.

Common questions

What is the difference between no-cache and no-store?

no-cache lets a cache store the response but requires it to check with the server before every reuse, so unchanged content comes back as a cheap 304 Not Modified. no-store forbids storing the response at all, so every visit downloads it in full. Use no-cache for HTML that must stay current, and no-store only for sensitive or personal data.

What is the best Cache-Control header for static assets?

For assets with a content hash in the filename, use public, max-age=31536000, immutable. This caches them for a year, and supporting browsers skip revalidation, even on reload. Use this only on fingerprinted URLs. Unversioned files need a moderate lifetime plus an ETag or Last-Modified.

Should HTML pages be cached?

Usually they should be revalidated rather than cached for long periods. Cache-Control: no-cache with an ETag keeps pages current while unchanged pages return 304. A few minutes of max-age is fine for rarely updated public pages. Signed-in pages need private, and pages with sensitive data need no-store.

Is an ETag enough without Cache-Control?

It allows conditional requests, but without explicit directives caches fall back to heuristics, so behaviour varies between browsers and CDNs. Send both: Cache-Control to state the policy and an ETag or Last-Modified to make revalidation cheap. Sitelemetry does not raise delivery.caching.missing when a validator is present.

Does my CDN follow my Cache-Control headers?

It depends on the provider and on your settings. Many CDNs cache static file types by default but not HTML, and some override origin lifetimes with dashboard rules. Use s-maxage or CDN-Cache-Control to set edge lifetimes explicitly, and check the Age and cache status headers to see what actually happens.

Sources & further reading

  1. RFC 9111: HTTP Cachingwww.rfc-editor.org
  2. RFC 9110: HTTP Semantics (validators and conditional requests)www.rfc-editor.org
  3. RFC 8246: HTTP Immutable Responseswww.rfc-editor.org
  4. RFC 9213: Targeted HTTP Cache Control (CDN-Cache-Control)www.rfc-editor.org
  5. MDN: Cache-Control headerdeveloper.mozilla.org
  6. web.dev: Prevent unnecessary network requests with the HTTP Cacheweb.dev
  7. Chrome for Developers: Serve static assets with an efficient cache policydeveloper.chrome.com
  8. nginx: ngx_http_headers_module (add_header, expires)nginx.org
Sitelemetry team

Prepared by the Sitelemetry editorial team. Explore the linked sources for further detail.

SITELEMETRY

Put what you learned to work.

Explore your website’s structure, settings and signals with Sitelemetry.