Mirage CDN
HTTP caching / field guide 10

What immutable and max-age really do

Use long-lived caching for versioned assets, understand the limits of immutable, and design releases that remain correct during updates.

By Mirage CDN · Updated

max-age and immutable work together, but they communicate different things. One describes a freshness lifetime. The other says the representation will not change during that lifetime. Their value depends on a release process that respects the promise made by the response headers.

For developers delivering public static assets, the important question is whether a particular URL will continue to identify the same bytes. A long lifetime is appropriate only when the update and recovery process can support it. The examples here are illustrative policy choices, not active service settings.

Read the two directives separately

Consider this response policy for a versioned asset:

Cache-Control: public, max-age=31536000, immutable

The lifetime is 31,536,000 seconds. HTTP caching still involves storage eligibility, current age and request requirements; this header does not force a cache to retain the file for that entire period. Caches can discard stored responses. A later request may therefore need the origin even before the lifetime ends. HTTP caching guide

RFC 8246 defines immutable as a promise that the representation will not be updated during its freshness lifetime. A supporting client should skip unnecessary conditional revalidation while that response is fresh. The extension does not assign a lifetime itself, and it has no effect when placed in a request. RFC 8246

Do not read the sample as “retain this file permanently.” Instead, make two separate acceptance checks: the server sends the intended freshness policy, and the release process never overwrites that asset URL with different content during the promised interval.

Make a changed file a changed URL

Suppose a build produces /assets/navigation.a73c92.css. When the stylesheet changes, the next build produces /assets/navigation.d46b10.css. The HTML document selects the correct filename. This versioning pattern lets an older document and a newer document refer to their respective assets without requiring the old URL to change meaning. HTTP caching guide

Treat the filenames in this example as invented identifiers, not calculated digests. In a real build, use the build system’s content-fingerprinting process and retain a manifest linking source files to emitted assets. Test that changing the source changes the referenced output and that an unchanged asset retains its intended identity.

Publish the new assets before publishing documents that refer to them. During a rehearsal, pause between those steps and request the new asset directly. Then publish the document and inspect every referenced file. This sequence turns a vague release operation into two reviewable transitions.

Give the referring document its own policy

An HTML document that chooses the current asset version is usually mutable. Give it a policy suited to how quickly updates must become visible. Do not copy the immutable asset policy to the document merely because both files came from the same build directory.

For a document that should validate before reuse, an illustrative policy is Cache-Control: no-cache. A validator such as an entity tag lets a conditional request ask whether the stored representation remains suitable. If-None-Match can lead to 304 Not Modified for an unchanged GET response; changed content requires the appropriate new representation instead. If-None-Match reference

Test the document and asset separately. Update a visible sentence without changing the stylesheet and confirm that the document changes while the asset URL remains stable. Then change the stylesheet and confirm the new document selects the new URL. The two tests expose different mistakes.

Keep recovery possible

An accidental overwrite is a release defect even if a fresh browser happens to show the replacement. A visitor holding the previous fresh representation may continue using it. Correct the release by producing a new asset URL and updating the referring document, then verify the transition with both an existing session and a new session.

Retain old assets for a documented transition period. For a hypothetical application with long-lived open documents, deleting the previous release immediately would make later requests from those documents difficult to support. Choose retention with the application owner, include storage cleanup in the runbook, and rehearse rollback before relying on it during an incident.

immutable also has security limits. RFC 8246 recommends ignoring it outside an authenticated context such as HTTPS and allowing force-reload mechanisms to bypass it. It does not make corrupted content trustworthy or replace transport authentication. RFC 8246, security considerations

For supported subresources, Subresource Integrity supplies a separate mechanism: the document supplies integrity metadata and the user agent checks the response against it. A digest embedded only in a filename does not itself ask the browser to perform that verification. Subresource Integrity specification

Rehearse the complete lifetime

Use a short lifetime on a disposable fixture so expiry can be observed during a test. Exercise first retrieval, reuse while fresh, validation after expiry, a changed document and a missing old asset. Repeat with the relevant browser settings rather than relying exclusively on a command-line request.

For the real release, retain the exact output manifest, response headers and observed results. Mark untested browsers or delivery layers explicitly. A build can prove that names were generated; only an integration check can show that the deployed document references them and receives the intended policy. Keep those evidence layers distinct when deciding whether the release is ready.

Sources

This guide explains technical concepts. For your delivery setup, review the documentation and request an account from our team.

Read the integration docs · Explore more CDN guides