Free SEO audit for new clients — claim yours
Home/Blog/Technical SEO/Browser Caching: How to Set It Up for Faster Rep…
Technical SEO

Browser Caching: How to Set It Up for Faster Repeat Visits

Browser Caching: How to Set It Up for Faster Repeat Visits
Table of contents
  1. Key Takeaways
  2. How Browser Caching Works
  3. Cache-Control Directives Explained
    1. Validation: ETag and Last-Modified
  4. A Practical Caching Strategy by File Type
  5. How to Set Up Browser Caching (Step by Step)
    1. Apache example
  6. Don't Forget the Back/Forward Cache
  7. Does Browser Caching Help SEO?
  8. Common Mistakes
  9. Related Guides
  10. Frequently Asked Questions
    1. What is a good max-age for static files?
    2. What is the difference between no-cache and no-store?
    3. Does browser caching improve Core Web Vitals?
    4. How do I clear users' cached files after an update?
    5. Is browser caching the same as a caching plugin?
  11. Conclusion
  12. References

The fastest request is the one that never happens. When a visitor comes back to your site, or clicks through to a second page, their browser can reuse files it has already downloaded: your stylesheet, your logo, your fonts, your JavaScript bundles. Whether it actually does depends almost entirely on a few HTTP headers.

Browser caching is one of the oldest performance techniques on the web, yet misconfigured cache headers are still everywhere. Some sites cache nothing, forcing repeat downloads; others cache HTML so aggressively that visitors see stale prices or old navigation for days.

This guide explains how the HTTP cache works, which Cache-Control settings to use for different file types, how to set them up on common servers and CDNs, and how to test that your caching is doing what you expect.

Key Takeaways

  • Browser caching lets repeat visitors reuse files instead of downloading them again, cutting load times and server load.
  • Use long lifetimes, such as max-age=31536000, only for versioned (fingerprinted) files whose URL changes when content changes.
  • Use no-cache (revalidate before use) for HTML and other unversioned files; it does not mean "do not cache".
  • Prefer ETag for validation and avoid relying on browsers guessing cache lifetimes.
  • The back/forward cache (bfcache) is separate from the HTTP cache and is easy to block by accident.

How Browser Caching Works

When a browser requests a file, the server's response headers tell it whether the file can be stored, for how long, and how to check later whether it has changed. On the next request for the same URL, the browser looks in its HTTP cache first. If the stored copy is still "fresh", it is used immediately with no network trip. If it is "stale", the browser asks the server whether it has changed; a 304 Not Modified answer lets it reuse the stored copy.

A common myth is that leaving out cache headers disables caching. web.dev's HTTP cache guide points out the opposite: omitting Cache-Control does not disable HTTP caching, and browsers effectively guess a lifetime instead. Guessing is not a strategy, so set headers explicitly.

Cache-Control Directives Explained

DirectiveWhat it meansTypical use
max-age=NThe response is fresh for N secondsStatic assets
immutableThe file will not change during its lifetime, so skip revalidation (ignored by some browsers)Fingerprinted CSS/JS/fonts
no-cacheStore it, but revalidate with the server before every useHTML pages
no-storeNever store any version, in the browser or in CDNsSensitive, personalised responses
privateBrowser may cache; shared caches such as CDNs may notLogged-in pages
publicAny cache may store the responsePublic static files

“This instructs the browser that it must revalidate with the server every time before using a cached version of the URL.”

— web.dev, describing no-cache, Prevent unnecessary network requests with the HTTP Cache

Validation: ETag and Last-Modified

Revalidation needs something to compare. An ETag is a token (usually a hash of the file contents) that the browser sends back in an If-None-Match header. Last-Modified uses a timestamp instead. web.dev recommends ETag because it is more accurate. Note that revalidation still costs a round trip, even if the 304 response is tiny, which is why long lifetimes on versioned assets matter so much.

A Practical Caching Strategy by File Type

The pattern used by most high-performance sites is simple: give every static asset a unique, versioned URL (for example app.3f9a1c.js), cache those for a year, and keep HTML short-lived so it can point to new versions instantly.

File typeRecommended headerWhy
HTML documentsCache-Control: no-cache (or a short max-age)Content changes; users must see updates
Versioned CSS and JSCache-Control: public, max-age=31536000, immutableURL changes whenever content changes
Web fonts (versioned)public, max-age=31536000, immutableFonts rarely change; see web font optimization
Images with versioned URLspublic, max-age=31536000Large files, big savings on repeat views
Unversioned images or logosA few days to weeks, with ETagBalance freshness and reuse
Account, cart and checkout pagesprivate, no-cache or no-storePersonal or sensitive data
robots.txt and sitemapsShort lifetimeChanges should be picked up quickly

How to Set Up Browser Caching (Step by Step)

  1. Check your current headers. In Chrome DevTools, open the Network tab, click a file and read the Response Headers, or run curl -I https://example.com/style.css.
  2. Turn on asset fingerprinting. Most build tools (Vite, webpack and many CMS optimisation plugins) can add a content hash to file names.
  3. Configure long-lived headers for fingerprinted assets. On Apache, use mod_headers or mod_expires in .htaccess; on Nginx, add an expires or add_header Cache-Control rule for asset paths.
  4. Set HTML to revalidate. Use no-cache or a short max-age so updates appear immediately.
  5. Align your CDN. Make sure the CDN respects or overrides origin headers deliberately, and purge it on deploys. If your origin is hard to change, headers can also be set at the CDN layer, as explained in our guide to edge SEO. Our CDN SEO guide covers this layer.
  6. Protect private pages with private or no-store.
  7. Test a repeat visit. Reload the page and confirm static assets show "(memory cache)" or "(disk cache)" in DevTools.
  8. Re-run a Lighthouse report. Since Lighthouse 13, the old long-cache audit appears as a "use efficient cache lifetimes" insight; see our Lighthouse audit guide.

Apache example

<FilesMatch "\.(css|js|woff2|webp|avif)$">
  Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
<FilesMatch "\.html$">
  Header set Cache-Control "no-cache"
</FilesMatch>

Only use the one-year rule if those files are fingerprinted. If your CSS is always called style.css, a year-long cache will trap users on old styles. If you edit .htaccess regularly, our guide to .htaccess redirects covers safe editing habits.

Don't Forget the Back/Forward Cache

The back/forward cache (bfcache) is a different mechanism: web.dev describes it as a snapshot of the entire page in memory, which makes back and forward navigation instant. It is easy to block without realising.

“The most important way to optimize for bfcache in all browsers is to never use the unload event.”

— web.dev, Back/forward cache

web.dev also notes that pages served with Cache-Control: no-store have historically been excluded from bfcache by browsers, which is another reason to reserve no-store for truly sensitive pages.

Does Browser Caching Help SEO?

Caching mainly benefits returning visitors and multi-page journeys, which shows up in real-user Core Web Vitals data rather than in a single lab test. Faster repeat views support the user experience signals described in our Core Web Vitals guide. Googlebot has its own caching behaviour, but sensible headers and stable resource URLs also help keep crawling efficient, as explained in our crawl budget guide.

Common Mistakes

  • Long lifetimes on unversioned files, so users keep seeing old CSS or JavaScript after a release.
  • Caching HTML for hours or days, leading to stale prices, stock levels or menus.
  • Thinking no-cache means "never cache". That is no-store.
  • Using no-store everywhere, which forces full re-downloads and can block bfcache.
  • Letting the CDN and origin disagree, so debugging becomes guesswork.
  • Caching error pages. A cached 5xx response can turn a short outage into a long one; see our guide to 5xx server errors.

Frequently Asked Questions

What is a good max-age for static files?

For fingerprinted files whose URL changes with every update, one year (max-age=31536000) is the widely recommended value. For unversioned files, use a much shorter lifetime with ETag validation.

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

no-cache lets the browser store the file but requires it to check with the server before reuse. no-store forbids storing the response anywhere.

Does browser caching improve Core Web Vitals?

It can improve real-user metrics for repeat visits and multi-page sessions because fewer resources need downloading. It does not change the first visit.

How do I clear users' cached files after an update?

You cannot reliably clear a visitor's cache remotely. Instead, change the file name or add a version hash so the HTML points to a new URL.

Is browser caching the same as a caching plugin?

Not exactly. Many WordPress caching plugins mainly create cached HTML on the server, and some also set browser cache headers. Check the actual response headers to see what is happening.

Conclusion

Good browser caching follows one rule: cache versioned assets for a very long time and keep HTML fresh. Add explicit headers, fingerprint your files, keep no-store for sensitive pages and check the bfcache, and repeat visitors will feel the difference.

If you would like experts to configure caching, CDN and server settings together, our page speed optimization service can help. Request a free quote today.

References

  1. Prevent unnecessary network requests with the HTTP Cache – web.dev
  2. Love your cache – web.dev
  3. Back/forward cache – web.dev
  4. Lighthouse 13.0 release notes – Chrome for Developers
  5. What Is Page Speed & How to Improve It – Semrush Blog
Rohit Choudhary
Written byRohit ChoudharyCo-Founder, My SEO Experts

Rohit Choudhary is the co-founder of My SEO Experts and has more than 14 years of hands-on experience in SEO, paid advertising and digital marketing. Since starting out in 2011 he has helped hundreds of businesses grow through practical, data-driven search strategies, and he also serves as a consulting Digital Marketing Director for several US-based companies.

Keep reading

Related articles

How to Set Up 301 Redirects in .htaccess
Technical SEO

How to Set Up 301 Redirects in .htaccess

Copy-ready .htaccess rules for the 301 redirects you actually need, explained line by line, with a safe process for testing them before Google sees them.

400 Bad Request Error: Causes and How to Fix It
Technical SEO

400 Bad Request Error: Causes and How to Fix It

A 400 Bad Request error means the server refused a request it considered malformed. Here is how to find the cause, fix it as a visitor or site owner, and protect your SEO.

Ready to grow your business online?

Get a free, no-obligation proposal tailored to your goals and budget.

CallFree Quote