How the web works · Concept

Caching

Keeping a copy of something that was slow or costly to fetch or build, so the next request can be answered quickly from the copy.

Requests and responses · updated

How it works

Caches sit at every layer. The browser keeps images, scripts and pages according to the Cache-Control header; a CDN keeps copies in data centres near visitors; the server caches rendered pages or API results; and a store such as Redis holds the results of slow database queries. Each hit saves time, bandwidth and money.

The hard part is freshness. Lifetimes (max-age), revalidation (an ETag and a 304 'not modified' reply) and fingerprinted file names such as app.3f9a1c.js let files be cached for a year yet replaced the moment they change. Anything personal, such as a basket or an account page, must be marked private or no-store, or a shared cache could show one visitor's data to another.

More in How the web works

Requests and responses

All 20 How the web works terms

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.