Skip to main content
SlapMyWeb

Performance fix

How to Add Browser Cache Headers

Tell browsers to cache static assets so repeat visits load almost instantly.

Difficulty
Medium
Impact
Medium
Time
15 min

Before

# No Cache-Control on /static/* assets

After

# Fingerprinted assets
Cache-Control: public, max-age=31536000, immutable
# HTML documents
Cache-Control: public, max-age=0, must-revalidate
Before and after code for: How to Add Browser Cache Headers

Without cache headers, browsers download the same CSS, JavaScript and images on every visit. Give fingerprinted files a long Cache-Control lifetime with the immutable flag, and keep HTML short-lived or revalidated so new releases still reach visitors. Repeat visits then load almost entirely from the local cache.

Why it matters

Without cache headers, the browser re-downloads your CSS, JS and images on every visit. Long-lived caching for fingerprinted (hashed) assets makes repeat visits near-instant and cuts server load.

How to fix it

  1. Cache hashed assets forever

    Assets with a content hash in the filename can be cached for a year with immutable: a new deploy gets a new filename.
  2. Keep HTML fresh

    HTML should use a short max-age (or no-cache) so users get new content while assets stay cached.

The code

Beforehttp
# No Cache-Control on /static/* assets
Afterhttp
# Fingerprinted assets
Cache-Control: public, max-age=31536000, immutable
# HTML documents
Cache-Control: public, max-age=0, must-revalidate

On your platform

WordPress

A caching plugin or your CDN sets far-future expiry on static files. Confirm in DevTools → Network that assets return cache-control: max-age.

Next.js

Next.js already serves /_next/static with immutable long cache; configure other static files in your proxy.

Sources

Check your site with our free tool

HTTP Header Checker

Fixed that one.
Now find the rest.

A free audit ranks every issue on your site by the score points it costs, and links each one straight to its guide.

Run a free audit
Free foreverNo signupLive scan progress
How to Add Browser Cache Headers — Fix Guide | SlapMyWeb