What Is Browser Caching?

Category: Performance & CDN ยท Updated 2026-11-01

Browser caching is when a visitor's browser stores a copy of static files, such as images, CSS and JavaScript, on their own device after the first visit. On later visits, the browser reuses the stored copy instead of downloading the file again, which speeds up page loads and reduces requests to your server. It is controlled through HTTP headers such as Cache-Control and Expires.

How browser caching works

  1. A visitor loads a page for the first time, and the browser downloads images, CSS, JavaScript and fonts.
  2. The server's response includes caching headers that tell the browser how long it may keep each file and how to re-check it.
  3. The browser stores a copy locally, tagged with that expiration information.
  4. On the next page or next visit, if the stored copy has not expired, the browser uses it directly instead of asking the server again.
  5. Once the file expires, the browser either re-downloads it or sends a quick check that lets the server reply "unchanged" without resending the whole file.

The headers that control it

HeaderPurpose
Cache-ControlMain control: max-age (seconds to keep), public/private, no-cache, no-store
ExpiresOlder header giving an exact expiration date; Cache-Control takes priority when both are present
ETagA fingerprint of the file's content, used to check if it changed without resending it
Last-ModifiedThe file's last change date, used for the same kind of check as ETag

When a cached file's expiration has passed, the browser can send a conditional request with the stored ETag or Last-Modified value. If the file has not changed, the server replies with a lightweight 304 Not Modified status and no file body, which is much cheaper than a full re-download.

Setting cache headers on your server

On Apache, using mod_expires and mod_headers in .htaccess:

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

On Nginx, inside a server block:

location ~* \.(jpg|jpeg|png|gif|css|js)$ {
    expires 30d;
    add_header Cache-Control "public, immutable";
}

Many WordPress caching plugins and most CDNs also offer a setting to apply sensible cache headers automatically without editing server configuration directly.

Choosing cache lifetimes

  • HTML pages: usually short or no browser caching, since content changes and visitors expect to see updates.
  • CSS and JavaScript with a version or hash in the filename: can be cached for up to a year safely, because a change to the file produces a new filename, so there is no stale-content risk.
  • Images, fonts and other rarely-changing assets: commonly cached for weeks to a year.
  • Files that change often without changing their filename: use a shorter cache time or a revalidation strategy to avoid visitors seeing an outdated version.

Browser caching vs. other kinds of caching

Browser caching only helps repeat visits from the same device, since a brand-new visitor has nothing stored yet. It is different from a CDN, which caches copies closer to every visitor's region and helps first-time visits too, and from server-side page caching, which stores a ready-made version of a dynamic page so the server does not rebuild it from scratch each time. A fast site typically uses browser caching, CDN caching and server-side caching together, each covering a different gap.

Frequently asked questions

What is browser caching?

Browser caching is the browser's practice of storing a copy of static files like images, CSS and JavaScript on the visitor's own device, so repeat page views can reuse them instead of downloading them again.

Does browser caching help first-time visitors?

No. A first-time visitor has nothing cached yet, so their initial load downloads everything normally. The benefit shows up on their second page view or return visit.

How do I set browser cache headers?

On Apache, use mod_expires and mod_headers directives in .htaccess or the server config; on Nginx, use the expires directive inside a location block. Most caching plugins and CDNs can also set these headers for you.

What is the difference between browser caching and a CDN?

Browser caching stores files on an individual visitor's device and only helps that visitor's repeat views. A CDN stores copies on servers around the world and can speed up even a visitor's very first request by serving from a nearby location.

How long should static files be cached in the browser?

Files with a version or hash in the filename, such as style.a1b2c3.css, can be cached for up to a year since any update changes the filename. Files without versioning are usually cached for a shorter period, such as a few weeks, to limit how long an update takes to reach returning visitors.

Why do I need to clear my browser cache after a website update?

If a changed file keeps the exact same filename and was cached with a long expiration, your browser may keep showing the old stored copy until it expires or you clear the cache, which is why developers recommend versioned filenames instead.

Related topics