Web development

HTTP caching

HTTP cache allows you to reuse a previously downloaded response according to the rules provided in the headers. It can run in a browser, intermediary or CDN.

Published: Updated: 3 min read
Schema: HTTP Cache - page cache. Answer - Memory - Reuse.

What is HTTP cache?

HTTP cache allows you to reuse a previously downloaded response according to the rules provided in the headers. It can run in a browser, intermediary or CDN. Limits transfer and number of requests to the source, but requires currency and privacy control. Not every answer is suitable for sharing. A public image and a private client side have completely different needs, even though both resources technically return code 200.

Cache-Control and expiration time

Directives specify who can store a response and when it must be checked for validity. No-cache does not mean a simple write ban: it requires validation before reuse. No-store refers to not storing within the cache mechanism. Distinguish between private and public and rules for the shared layer. Don't copy a setting from an image to the HTML of your entire store without analyzing the content, headers, and how the infrastructure works.

Validation and 304 response

ETag or Last-Modified may allow the customer to query whether the version they have is still current. If the conditions are met, the server may respond with a 304 without resending the entire body. The identifier must correspond to the actual representation and the change dates should not be random. Correct validation reduces the transfer, but still requires a request. Don't treat it as the same as using a fresh resource without contacting the source.

Versioning and publishing

Long storage times can be planned for static files with version in their name. Changing the content should then change the address so that the client downloads the new file. With HTML you need a different refresh and invalidation plan. After implementation, check the consistency of scripts, styles and data. Clearing the local browser does not automatically remove copies on the CDN or other tiers, so some recipients may still be affected by the error.

Privacy and cache key

The key decides which requests can use the same response. Incorrect omission of language, authorization or user state may show incorrect content. On the other hand, including every random parameter can almost disable caching effectiveness. Identify the differences that actually change the answer. Apply appropriate policies and tests to private data, rather than assuming that using HTTPS alone protects shared storage.

How to test cache?

Check the first and subsequent requests, headers, content change, and post-expiration behavior. Test different languages, login and important parameters. Compare the source's response to the proxy's response, including available diagnostic headers. Measure transfer, latency and correctness, not just hit percentage. A good cache speeds up access to the correct version of information, rather than perpetuating an error or revealing someone else's data for a better performance result.

Example of a problem after the release of a new version

New HTML can point to an old script or an old copy of HTML to a new data set with a different format. Simply refreshing an artist's browser does not confirm consistency across all recipients. Version resources and determine the order of publication and cache invalidation. For long-stored files, do not overwrite content at an address that you want to remain immutable without a plan to download a new version.

Check the rules for language, login and private data. Vary and proxy key must match actual differences, but not every random parameter should create a separate copy. When validating, make sure that the ETag or Last-Modified changes with the correct representation. A 304 response does not indicate a retention ban and is not the same as no network request.

Sources and further reading

Use the primary documentation to check the principles and limitations described in this article.

How we prepare the glossary

These articles combine original editorial work, AI support for editing and translation, and checks against linked primary documentation. Examples are illustrative unless stated otherwise; they do not represent client results. Dates refer to publication and actual content changes.

From knowledge to action

Need help putting this into practice?

Tell us about your website or process. We will define the scope and the next practical step.

Discuss your project