When a visitor loads your page, their browser downloads every image, stylesheet, and script. Browser caching tells the browser to keep those files so the next visit, and the next page, loads almost instantly. This is the fix behind “leverage browser caching” and “serve static assets with an efficient cache policy” in speed tests.
What caching does
Each static file can carry an expiry. With a far-future expiry, the browser reuses its saved copy instead of downloading again. Repeat visits get dramatically faster, and your server serves less traffic.
Add the rules
- Open the .htaccess Browser Caching Generator.
- Choose how long each file type should be cached.
- Copy the generated block into the
.htaccessfile at your site root.
The rules are built in your browser; nothing is uploaded.
How long to cache what
- Images, fonts, video: a long time (up to 1 year). They rarely change.
- CSS and JS: long, if the file names change when you update them (most build tools add a hash). If not, use a shorter window like a month.
- HTML: short or no caching, so content updates show right away.
The trick for safe long caching
The reason you can cache CSS and JS for a year is fingerprinting: the file name changes when the content changes (style.abc123.css). The browser treats the new name as a new file and fetches it. If your file names are fixed, keep the cache shorter so updates are not stuck behind an old copy.
Pair it with compression
Caching and gzip are the two halves of the static-asset speed fix. Turn on both.
Related tools
- Enable compression with the .htaccess Gzip Compression Generator.
- On Nginx instead? Use the Nginx Browser Caching Generator.
- Measure the impact with the Page Size & Request Analyzer.
Set long expiries for static files, keep HTML short, and pair it with gzip. Repeat visits get much faster.