Cache lifetime for static files

How the scan finds images, scripts, styles and fonts with a short cache lifetime, which files it skips, and how to set a long max-age without breaking updates.

What AuditX checks

The scan loads the page you scanned once in a real browser with Lighthouse and looks at the files it downloaded. It only considers images, fonts, media files, scripts and stylesheets that answered with status 200, 203 or 206. A video that loads in parts (status 206) makes several requests for the same file; the scan counts it as one file and adds up its bytes. For each file it reads max-age from the Cache-Control header, or the Expires header when there is no max-age. A file with no cache header at all counts as a lifetime of zero. Lighthouse turns the lifetime into an estimated chance that a returning visitor still has a fresh copy. A file is listed when that chance is 92.5 percent or lower. A max-age of one year is well above that limit. Files are skipped when Cache-Control contains must-revalidate, no-cache, no-store, private or stale-while-revalidate, when only a Pragma no-cache header is present, or when max-age is 0 or the Expires date is in the past. A file on another domain than your site, such as an analytics script, a chat widget or a font service, is counted separately, because its owner sets its headers. A file on a subdomain of your own domain, such as a CDN subdomain, counts as yours. The check warns when at least one of your own files is listed with a lifetime under a week. It gives an info note, which does not lower the score, when every listed file of your own is cached for a week or more, because a visitor who comes back within that time still reuses it, and also when every listed file comes from another site. It passes when none is listed. The message gives the number of your own files under a week, the three of them that waste the most data, how many of your own files are cached for a week or more, how many more come from other sites, an estimate of the kilobytes your own files cost per repeat visit on average (the file size times the chance it has expired). That estimate is an upper bound: it counts every expired file as a full download, while a file whose server sends an ETag or Last-Modified header can be confirmed as unchanged with a short check, and a browser may keep a file with only a Last-Modified header for a while on its own guess. The scan does not read those headers. When those re-downloads come to 0.1 gram of CO2e or more per visit, the message also gives that modelled carbon figure, marked as modelled, not measured. If Lighthouse fails on this audit, the check is shown as not measured and is left out of the score. If Lighthouse cannot run at all, one general not-measured note replaces it. If Lighthouse gives no result for this audit, the check does not appear. Only the one page is tested. The HTML page itself, data requests, and files that Lighthouse did not load are not tested.

Why it matters

When a file has a short cache lifetime, the browser has to ask for it again on later visits and on other pages of your site, and may download it again. With a long lifetime it reuses the copy it has. That makes repeat visits faster and uses less data.

The web.dev guide on HTTP caching advises a one year max-age (31,536,000 seconds, the maximum) for files whose address contains a version or fingerprint and that never change. It also explains the catch: browsers keep using a cached copy until it expires, so a changed file needs a new address, or visitors keep the old one.

How to fix it

  1. Look at the files named in the result. Files on your own site, such as your images, scripts, stylesheets and fonts, you can fix. Files from other sites are set by their owners, so leave those.
  2. Give your static files a version or a hash in the file name, for example style.x234dff.css, so that a new version always has a new address. Many build tools and caching plugins do this for you.
  3. Then set a long lifetime on those files in your server, CDN or hosting settings. Do not set it on a file that keeps the same name after you edit it, because visitors will keep the old copy.
  4. Keep the HTML pages themselves on a short lifetime or on revalidation, so that visitors always get the links to the newest file names. Then scan again.
Cache-Control: public, max-age=31536000, immutable

Does your site pass this check? A free scan runs it with every other check and shows the result in about a minute.

Scan my site

Sources

Related checks

Last reviewed 2026-11-13.