HTTP caching is the process of storing copies of web resources such as scripts, stylesheets, and images on the client side or intermediary servers. It reduces the number of round trips to the origin server, minimizing network congestion and improving application performance.
How it works
Control is managed via specific headers like Cache-Control, ETag, and Expires. The max-age directive specifies how long a resource remains fresh. If the cache is stale, the client performs a conditional request using If-None-Match. The server responds with 304 Not Modified if the resource hasn't changed, saving bandwidth by not re-sending the file body.
- Private Cache: dedicated to a single user (browser cache).
- Shared Cache: located between the server and clients (CDN, ISP proxies).
It is essential for static assets and idempotent GET requests. CDNs utilize this mechanism to serve content from edge locations closer to the user, significantly reducing Time to First Byte (TTFB). Properly configured caching can reduce server load by up to 90% for static-heavy sites. Fetching a resource from a local browser cache typically takes less than 10ms, compared to hundreds of milliseconds for a standard network request.