Browser Caching
How Browsers Keep Files for Later
Browser caching is the storing of website files on a visitor's own device, so the browser can reuse them on later visits instead of downloading them again. It is one of the simplest and most effective forms of caching, because it removes the trip to the server entirely for files the browser already holds.
The browser decides what to keep based on instructions the server sends with each file. These instructions say whether a file may be stored and for how long. Files that rarely change, such as a logo, a font or a site-wide stylesheet, are the best candidates. A page's HTML is usually kept for a shorter time, because its content can change more often. The layers that make up caching as a whole are outlined in the guide to types of caching.
What Repeat Visits Gain
On a first visit, the browser downloads everything the page needs. On a second visit, it can load stored copies of unchanged files from the local cache and request only what is new or expired. The page appears sooner, and less data crosses the network.
This matters most on slow or metered connections, and for sites whose pages share the same assets. A visitor who browses several pages of one site uses the same stylesheet and logo each time, so after the first page those files load from the device.
Limits and Updating Stored Files
Browser caches are not permanent. A browser can remove stored files to free space, and visitors can clear them. A cached copy also stays in use until its lifetime ends, so a changed file may not reach a visitor until then.
Site owners handle this by giving changed files new names, a technique called cache busting. A stylesheet that is renamed when it changes forces the browser to fetch the new version, while the old copy is simply no longer requested. The exact header settings are explained in the article on cache-control headers.
Frequently asked questions
Does browser caching work on every visit?
No. It works for files the browser has already stored and that are still within their lifetime. The first visit always downloads files from the server. Some files, such as personal data or pages that must always be current, are not stored at all.
Can a visitor turn off browser caching?
Visitors can clear their browser cache at any time, which removes stored files and forces the next visit to download them again. Website owners cannot force a visitor's browser to keep files, but they can guide it using the cache instructions sent with each file.