Search
Enter at least two characters without personal information.

    LibraryArticles & FAQ Your projectRequest a quote
    LanguageEN
    Practical guides

    Configure HTTP caching without exposing private data

    Caching helps only when the reused response is appropriate for the visitor and the time of access. A single policy for every resource can hide an update or expose a personalised response.

    Go to the method

    Network equipment and laptop on a technical desk
    AI-generated illustration

    Classify responses before choosing a lifetime

    Inventory public pages, static assets, API responses, accounts and confirmations. Record whether each changes with the user, language or a parameter. Identify browser, intermediary and CDN caches. An account page should not inherit the policy of a public photograph merely because that policy is easy to apply.

    Distinguish freshness from permission to store a response. MDN explains that no-cache requires revalidation, whereas no-store requests no storage. private restricts storage to private caches. A cookie alone does not automatically make a response private.

    Plan how an update becomes visible

    Write an update rule for each family. For a versioned file, confirm that the new page requests the new URL. For a public page with a stable address, describe revalidation or purging. A long lifetime without a replacement procedure only moves the problem to the next content change.

    Choose a practical example: a price correction, opening hours or a replaced document. Record when the origin changes, then inspect a session that has already visited the page. A fresh browser alone does not cover a returning visitor retaining an earlier response.

    During revalidation, the browser can send the ETag of its stored copy in If-None-Match. If the representation still matches, a 304 response allows reuse of the stored body; it does not deliver a new page body. If the representation has changed, a complete 200 response can deliver the content and its new validator. An isolated status code therefore does not describe what the visitor ultimately sees.

    If the first response includes Last-Modified, copy that date exactly into If-Modified-Since in a second GET to the same URL. A 304 means the server’s modification date is no later than the date supplied. If two versions are served within the same second, the dates can match even though the content changed. Use an ETag that distinguishes the versions when that precision matters. If the request includes both conditional fields, If-None-Match takes precedence.

    The table uses fictitious validators demo-v1 and demo-v2 to distinguish stages, without measuring this site. Keep the conditional request, response, reused copy and displayed correction together. An ETag is an opaque server-generated identifier, not necessarily a hash or date. Also check Back navigation: history may restore a snapshot through a mechanism separate from the HTTP cache.

    Scroll the table horizontally to read every column. With a keyboard, focus the table area and use the arrow keys.

    Fictitious example: follow revalidation through to displayed content
    Test situationExchange to connectUseful evidence
    First read200 with a body and ETag demo-v1.The initial copy contains the expected version.
    Revalidation without a changeIf-None-Match demo-v1, then 304.The stored body is reused; no new body is received.
    Changed representationIf-None-Match demo-v1, then 200 with demo-v2.The new body is received and the correction is actually visible.
    A 304 response observed aloneThe response must be connected to the stored copy.The code alone proves neither content recovery nor display of the correct variant.

    Test different identities and states

    On a test environment, compare an anonymous visit, two distinct accounts, logout and back navigation. Inspect the displayed content and received headers rather than only the hosting configuration. Use synthetic test records instead of real personal documents.

    Include relevant language, device, filter and error states. Keep the URL, session state, expected response and result for each test. When personalisation passes through a shared cache, have the infrastructure owner review cache keys and exclusions.

    Scroll the table horizontally to read every column. With a keyboard, focus the table area and use the arrow keys.

    Read cache directives without confusing them
    Situation or settingWhat it meansUseful check
    no-cacheStorage remains possible, but the response must be validated before reuse.Check revalidation after an update; do not treat this directive as no-store.
    no-storeInstructs caches not to store the response.Also check existing cache layers and the policy for sensitive pages.
    privateProhibits shared-cache storage while allowing a private cache.Test with two separate accounts, then anonymously.

    Keep a recovery procedure

    Document who can purge the cache, verify its effect and restore a previous configuration. A broad purge may temporarily reduce caching benefits, so prepare a check of essential pages after the operation.

    Review the policy when customer accounts, commerce, a language or a CDN is introduced. A useful deliverable is a response–policy–test–owner matrix. A performance score alone establishes neither freshness nor isolation between users.

    Primary documentation : MDN : HTTP caching.

    Prevent a shared cache from delivering the wrong representation.

    Synthetic case: one URL serves two formats according to a request header. Test both behind the actual cache and check the variation key, including Vary when relevant. Separate URLs may better suit editorial editions. Automatic negotiation must not make an explicitly selected version inaccessible.

    • Each request receives its intended representation, including after the other version with caching enabled.
    • MDN Content Negotiation

      Guide to selecting an HTTP representation according to client capabilities or preferences, including language, format and encoding.

    Separate public and private responses

    Two laptops distinguished by coloured markers beside a router
    AI-generated illustration · Observe content separately in two test sessions.

    Proposed case: a personalised confirmation is tested behind the same cache as public pages. Examine its content and headers in that exact journey.

    Compare request, response and reuse conditions with two isolated test sessions. Keep observed headers and content separation; a global cache rule does not validate every response.

    • Classify the response
    • Observe actual headers
    • Test separate sessions

    Reference documents

    Content updated on

    Documented reference points for this topic

    Documented reference points for this topic
    ReferenceValue or syntaxScope
    HTTP · 304
    If-None-Match → 304For a GET or HEAD request, an unchanged representation can be reused without resending its body.
    MDN · Vary
    Vary: Accept-LanguageWhen one URL produces different responses according to Accept-Language, Vary identifies that cache selection criterion. Keep the value consistent on 200 and 304 responses. Separate language URLs do not require this header merely because the website is multilingual.
    HTTP · If-Match
    If-Match: "r7" → 412If-Match compares a strong validator before a write. Under the illustrated contract, a stale version receives 412; keep the draft to compare changes.

    Dates indicate when references were consulted. These facts are neither a site audit nor an overall compliance statement.

    Read a cache revalidation

    Compare a replaced body with a reused copy. The excerpts show validators and available content, beyond the status code.

    These excerpts are incomplete and use demonstration addresses. The trial creates a Response in memory: it contacts no server and simulates neither network, cache nor business processing.

    200A new complete representation
    What it means
    In this excerpt, the server answers a conditional GET with a JSON body and the demo-v2 validator.
    What to check
    Compare If-None-Match, ETag and the body revision. The local trial parses the JSON supplied in this example.
    Watch out for
    A 200 status guarantees neither valid JSON nor correct business data. Successful parsing here does not validate your own data schema.
    Fictional exchange excerpt
    GET /demo/catalogue
    If-None-Match: "demo-v1"
    
    HTTP/1.1 200 OK
    ETag: "demo-v2"
    Content-Type: application/json
    
    {"revision":"demo-v2"}

    304Copy revalidated, no new body
    What it means
    304 answers a conditional request: the stored representation can be reused. The 304 response supplies no new body.
    What to check
    Compare the sent validator with the available demo-v2 copy. Correct interpretation also depends on that stored copy.
    Watch out for
    The trial constructs an isolated 304 Response, not an HTTP cache. During a real fetch, the browser cache can provide the stored response: network status and script-visible status can differ.
    Fictional exchange excerpt
    GET /demo/catalogue
    If-None-Match: "demo-v2"
    
    HTTP/1.1 304 Not Modified
    ETag: "demo-v2"

    Technical references : RFC 9110 §15 · MDN · Response.ok · MDN · Response.json() · WHATWG · Fetch · .

    Acceptance matrix to adapt to your project

    These proposed checks use synthetic cases. Decide the required behaviour with the team, record the result and assign unresolved gaps before release.

    Scroll the table horizontally to read every column. With a keyboard, focus the table area and use the arrow keys.

    Test cases, expected outcomes and useful evidence
    CaseExpected outcomeEvidence to retain
    Unchanged public pageAdvertised policy and conditional response remain consistent across requests.Public URL, Cache-Control, ETag or Last-Modified and response to the matching conditional request.
    Changed public contentThe corrected version arrives within the defined freshness conditions.Old and new content, request time and received headers.
    Two test accountsA personalised response for the first account is never served to the second.Isolated requests and content received by each synthetic account.
    Sign out and go backSensitive-screen behaviour matches the documented confidentiality requirement.Complete browser sequence and explicitly recorded limitations.

    Frequently asked questions

    How do you distinguish no-cache, no-store and private when testing?

    Inspect actual response headers, then repeat the request and change users in an authorised environment. no-cache permits storage but requires validation before reuse; no-store requests no storage; private prevents shared-cache storage. Check CDNs and intermediaries too: a configured directive does not establish the behaviour of the whole chain.

    How do you check an updated cached price?

    Publish a fictional price in a test environment and record its version. Change it, then inspect the page, any API and intermediary cache from fresh and existing sessions. Define the acceptable delay and invalidation method before publication. A new value visible to an administrator does not prove visitors already receive it.