Skip to content

How to set cache headers for static files

Best practices1 min readFixes check cache-headers

Cache-Control tells browsers how long to keep a file. Long lifetimes with versioned filenames make repeat visits instant.

Step by step, with screenshots: Apache .htaccess for an A grade: headers, redirects, caching →

Check your own site

Runs this check and the other 186, free, in about 45 seconds.

What a passing site looks like

  • Static files have a cache lifetimewarning · −1.5 ptseffort S

Cache lifetime for static files

Why it matters. Without a cache lifetime, every visit downloads the same logo, CSS and scripts again. Returning visitors should get them from their browser in 0 ms.

How to fix it.
  1. Send Cache-Control: public, max-age=31536000, immutable for versioned images, CSS, JS and fonts.
  2. Most caching plugins and CDNs set this for you; check the "browser cache" or "edge TTL" setting.

Filed under Best practices. Copy is generated from the same catalogue that scores every report, so what you read here is what the report says.