Lorixen.
EN

Cache-Control headers explained for a small website

Short answer: Caching headers tell browsers and CDNs how long they may reuse a file without asking your server again. Files whose names change when their content changes (fingerprinted CSS, JavaScript and images) can be cached for a year; HTML pages and anything without a version in its name should be revalidated, typically with no-cache plus an ETag or Last-Modified header, so updates show up straight away. Private pages such as account or checkout screens should be marked private or no-store.

Caching is one of the cheapest speed wins on a small site, and one of the most common reasons for "I updated the site but customers still see the old version". Both come down to the same few headers. This explainer covers what they mean, when they matter and a setup that works for most small business sites.

What caching headers are

When a browser downloads a file from your site, the server can attach instructions about storing and reusing it. The main one is Cache-Control. MDN's Cache-Control reference lists the directives; the ones a small site needs are:

  • max-age=N: the response stays fresh for N seconds; until then, caches can reuse it without contacting your server.
  • s-maxage=N: like max-age, but for shared caches (such as a CDN); private browser caches ignore it.
  • no-cache: the response may be stored, but must be revalidated with the server before each reuse. MDN stresses that this does not mean "don't cache".
  • no-store: don't store the response at all.
  • private: only the visitor's own browser may store it, not shared caches.
  • public: shared caches may store it.
  • immutable: the file will never change while fresh, so the browser needn't revalidate it.
  • must-revalidate: once stale, the response must be checked with the server before reuse.

How revalidation works

Revalidation is what makes no-cache fast. web.dev's guide to the HTTP cache explains that when a cached response has expired, the browser can send a small token (the ETag, usually a hash of the content) to the server; if it matches, the server says nothing has changed and the browser reuses its copy without downloading it again. Last-Modified does the same job with a date.

So no-cache with an ETag means: always check, but only download when something changed. For HTML pages, that's usually the right balance.

When it matters

  • Repeat visitors and multi-page visits: someone browsing five pages shouldn't download your logo, fonts and stylesheet five times.
  • Mobile visitors on weak signal: every avoided request helps.
  • After an update: badly set caching is why a fixed price or new phone number doesn't appear for some visitors.
  • With a CDN in front of the site: headers decide what the CDN keeps and for how long.

The two strategies web.dev recommends

web.dev describes two scenarios worth configuring.

Long-lived caching for versioned URLs. If a file's name contains a fingerprint or version number (for example style.x234dff.css) and its contents never change, cache it for a long time: web.dev's example is max-age=31536000, one year. When you change the file, the build gives it a new name, the HTML points to the new name, and visitors fetch it fresh. web.dev notes that adding immutable is a further optimization, though some browsers ignore it. MDN's "cache busting" example makes the same point with a version or hash in the filename or query string.

Server revalidation for unversioned URLs. HTML pages, and any file whose name stays the same when its content changes, should use no-cache (revalidate every time) and rely on ETag or Last-Modified to keep it quick. If a response must never be stored, use no-store.

A starting point for a typical small business site. Adjust with your developer or host.

File type Example Suggested Cache-Control Why
Fingerprinted CSS/JS app.4f9c2.css public, max-age=31536000, immutable Name changes with content
Fingerprinted images and fonts hero.8a1b.webp, font.woff2 (versioned) public, max-age=31536000, immutable Same reason
Unversioned images /uploads/team.jpg max-age of a day or a week, or no-cache Name may stay the same after a replace
HTML pages /, /services/, /contact/ no-cache (with ETag or Last-Modified) Updates appear on next visit
Logged-in pages, carts, checkout /account/, /checkout/ private, no-store Personal data; never in shared caches
API responses with live data stock levels, availability no-cache or short max-age Must stay current
robots.txt, sitemap.xml short max-age or no-cache Changes should be picked up

The "unversioned images" row is where small sites most often get caught: replace a photo with a new file under the same name, and visitors with a long max-age keep seeing the old one. Either upload replacements under new filenames or keep a short cache time for uploads.

Browser cache vs CDN cache

A CDN is a shared cache in front of your server. Two practical points:

  • s-maxage lets you give the CDN a different lifetime from browsers. For example, a CDN could keep an HTML page for a few minutes while browsers revalidate every time.
  • When you update content, a CDN may keep serving the old version until its copy expires, unless you purge it. Most CDN dashboards have a purge button; use it after big changes.

Never let a CDN cache pages that contain personal information. private or no-store on those responses prevents it.

Setting headers on common setups

  • Static site hosts and frameworks: many set long caching for fingerprinted assets automatically. Check what your host's documentation says about headers for HTML.
  • WordPress: headers usually come from the host, a caching plugin or both. Make sure only one layer sets them, or you'll get conflicting values, and check that cart and account pages are excluded from page caching.
  • Your own server: set rules by path or file type in the web server configuration.

To see what you're currently sending, open your browser's developer tools, go to the Network panel, reload, click a file and read the Response Headers.

Cache-Control: public, max-age=31536000, immutable

That's what a fingerprinted stylesheet should show. An HTML page should show no-cache and an ETag or Last-Modified header.

FAQ

Why do visitors still see the old version after I update?

Usually a file cached with a long max-age under an unchanged name, or a CDN that hasn't been purged. Version your files and purge the CDN after updates.

Is no-cache bad for speed?

Not with ETag or Last-Modified. The browser still reuses its copy when nothing has changed, after a quick check.

Should I cache HTML for an hour to speed things up?

You can at the CDN level with s-maxage, if you purge on updates. For browsers, revalidating HTML keeps content current.

Do caching headers affect SEO?

Treat them as a speed and freshness setting, not an SEO lever. Their main benefit is faster repeat visits.

A ten-minute look at your response headers often finds the reason updates seem to lag, so send us your site address and we'll suggest the caching rules to use.

Sources

WhatsAppLet’s talk