For small engineering teams, balancing immediate updates with long-term asset caching is a common challenge. This article outlines practical steps for setting up cache headers on static sites, using standard HTTP directives to ensure users receive fresh content while minimizing server load.
Assuming a Static Site Scenario
This is a hypothetical walkthrough, not a record of a real deployment. Picture a two-person engineering team preparing the launch of a documentation site for a home-lab hardware guide. The site is fully static: hand-written HTML pages, one stylesheet, one JavaScript bundle, a folder of SVG diagrams, and a set of downloadable PDF assembly sheets. Their hosting serves files from object storage behind a CDN, and they are configuring response headers at build and deploy time.
They sort every path by lifecycle rather than by file type. Three buckets emerge. First, hashed build outputs: the stylesheet, the script bundle, and any diagrams emitted by the build. Their names change whenever content changes. Second, stable-path assets: downloadable PDFs served from a fixed folder, which they expect to replace occasionally without changing the path. Third, HTML entry pages, including the home page and each guide page, which change with every editorial fix.
For the first bucket they write a header rule giving a one-year freshness lifetime and marking the response as immutable. Two example records in their deploy configuration look like this: path pattern /assets/, cache duration 31536000 seconds, immutable flag yes; path pattern /assets/, fallback for missing files, return a 404 without caching. For the second bucket they use a shorter lifetime, a week, plus an entity tag so conditional requests from repeat visitors can be answered without resending the file. For HTML they set no-cache with revalidation required, so browsers keep a copy but check back before reuse.
One early decision shows the trade-off they weighed. They considered applying the one-year immutable rule to the PDF folder as well, since PDFs rarely change. They rejected it because replacing an assembly sheet at an unchanged path would leave returning readers on a stale copy for up to a year, and those sheets carry hardware revision details worth keeping current. A one-week lifetime plus an entity tag was their compromise: fewer repeat transfers than no caching at all, but a bounded window for corrections.
They also draft three page names for their internal runbook: deployment header reference, asset naming rules, and cache troubleshooting notes. These names are their own working labels, chosen for clarity among two people, and they carry no claim about how any external tool displays or validates them. The point of the exercise is to make the three buckets and their lifetimes explicit before launch, then revisit the numbers once real traffic shows which assets actually change.
Defining Freshness and Validation Basics
RFC 9111 defines a cached response as fresh when it can be reused without validation, meaning the cache does not check with the origin server to confirm the response remains valid for the request; a fresh response can reduce both latency and network overhead. When a cached response is not fresh, RFC 9111 says it might still be reusable if validation can freshen it or if the origin is unavailable.1
The same document treats storage as conditional. A cache must not store a response unless conditions it lists are met, including an explicit expiration time or validator in some cases. RFC 9111 also notes that in normal operation some caches will not store a response that has neither a cache validator nor an explicit expiration time, because such responses are not usually useful to store, while caches are not prohibited from storing them.1
Before writing any header rule, you can sort your own files into a simple three-column table: path pattern, how often the content really changes, and which header choice you are leaning toward. For the stylesheet and script bundle with content hashes in their filenames, you might record a one-year freshness lifetime and mark those responses immutable, because a new build produces a new name. For the hand-written HTML pages, a short lifetime such as five minutes, paired with a validator, lets readers see edits soon without forcing a full re-download each visit.
The second column is where judgment matters. You can note the SVG diagrams and PDF assembly sheets as a middle case and decide per folder whether they change weekly or once a season. If you are unsure, consider a shorter lifetime plus validation rather than copying the one-year rule; a stale diagram is harder to notice than a stale stylesheet. You might write the reasoning beside each row so a future teammate can see why the choice was made.
Validation deserves its own line in your table. For each bucket, you can record whether the response carries a validator such as an ETag or Last-Modified value, and what a reader's browser should do when the cached copy is older than the lifetime. Keep this as notes for your own review; when a page feels slow or outdated after an edit, the table tells you which rule to revisit first.
Applying Long-Term Caching to Versioned Assets
MDN documents a cache-busting pattern for versioned static assets: add a version or hash to the filename or query string, such as the numbered library file and the picture URL with a hash parameter shown in its examples. Because that content is never modified in place and updated content gets a new URL, MDN says you can add a long max-age value and immutable; its example is a one-year max-age of 31536000 with immutable. MDN notes that immutable tells a cache the response will not be updated while fresh and avoids unnecessary conditional requests when a user reloads the browser.2
Once your versioned files are served with their one-year freshness rule, the next step is to keep the version identity visible in your own material. You can add a short note to each build output's filename or folder record showing the hash fragment and the date it entered the build. For example, a stylesheet entry in your notes might read: path pattern, hashed stylesheet; version marker, the hash suffix; first shipped, a date you fill in. Treat this as an author's example, not a measured result.
When a diagram or script changes, you can compare the old and new entries side by side before publishing. Consider writing the changed line as it would appear after the edit, then keeping the prior line beneath it with a label such as replaced on a given date. This makes it easier to confirm that a reference elsewhere still points to the same version, and it lets you decide whether the older entry should stay in your notes for rollback.
You might also draft a short internal line for teammates explaining why a filename carries a hash. A plain sentence such as the hash marks which build this file belongs to, so updates arrive under a new name, gives the reader a reason to leave the long lifetime alone. Whether to include such a line, and how much detail to add, remains your choice.
Handling HTML Entry Points with Revalidation
According to the HTTP caching reference, a no-cache response directive allows caches to store the HTML entry point but requires it to be validated with the origin server before each reuse. The reference states that the example header Cache-Control: no-cache applied to index.html makes the client receive a new version of the HTML response and static assets.2
The same source notes that no-cache does not mean "don't cache"; for preventing storage, no-store is the directive to use. It also warns that no-cache does not guarantee revalidation for history navigations, since a back/forward cache snapshot may be restored without revalidation.2
For your HTML entry points, consider a short freshness lifetime paired with revalidation rather than the long immutable rule you used for hashed assets. A practical starting point is a header value that lets a browser reuse the page only briefly — for example, max-age set to a small number of minutes — together with a validator such as an ETag, so a returning visitor can revalidate cheaply instead of downloading the whole page again.
You can make this concrete in your own notes by writing the rule as a small table. One row might read: path pattern, the index HTML files at the site root and under each section; change frequency, whenever the guide text or navigation is edited; header, short max-age plus revalidation; validator, ETag from the build output. A second row covers the PDF assembly sheets, marked as a separate case since they change on a different rhythm.
Before editing the deploy configuration, you might record two example URLs side by side: the HTML entry page and one hashed stylesheet. Note the version marker only in the latter, and decide whether that distinction is clear enough in your runbook. If it is not, adjust the wording rather than the rule.
Understanding ETags for Change Detection
ETag is an alternative validator to Last-Modified. Its value is an arbitrary one generated by the server, with no restriction on how it is produced — the server may base it on a hash of the body contents or a version number. When a cached response is stale, the client copies its stored ETag value into an If-None-Match request header to ask whether the resource has been modified; a 304 Not Modified comes back if the server's determined ETag matches, while a different ETag yields 200 OK with the latest version.3
For a 200 response, RFC9110 prefers that servers send both ETag and Last-Modified where possible, and during revalidation If-None-Match takes precedence over If-Modified-Since when both are present. The source also notes Last-Modified serves purposes beyond caching, such as CMS display of last-modified time and crawler frequency adjustment.3
For your HTML entry pages, you can pair the short freshness lifetime with revalidation, and ETags become the part of that rule you should think through yourself. When a page's bytes are republished identically, the server can answer a conditional request with a small not-modified response, so the browser reuses its copy. You might decide that automatic ETag generation is fine for hand-written pages, since any content edit will change the validator, and note that choice beside the row for your root index files.
You can test that reasoning on paper before publishing. Take one page, copy its current body text into a draft, change a single sentence, and ask which version an ETag computed from the file would identify. If the answer feels unstable because your build injects a timestamp into every page, consider removing that timestamp or documenting why validation will always miss; otherwise every visit re-downloads the page.
One caution deserves a line in your notes: an ETag is only as specific as what feeds it. A validator derived from modification time can flag unchanged files as new when a deploy touches them, while a content-derived one stays quiet. Either choice is yours, but record the consequence so a future teammate reading the rule knows what triggers a full response. You might keep this note short: ETag source, expected behavior on identical republish, and what a validator miss costs.
Avoiding Conflicting Cache Directives
Directives in one Cache-Control field must be comma-separated, and pairs that pull in opposite directions may be honored as the most restrictive one. The MDN reference gives an example combining private, no-cache, max-age=0, and must-revalidate; because no-store is also present, the example is described as equivalent to no-store alone.2
The reference also warns that a cache can store a response heuristically if no Cache-Control header is set, so caching requirements should be stated explicitly.2
For conflicting directives, you might first check whether your own published rules overlap in a way that changes the outcome. Take the three buckets you already sorted and write each intended response header directive as a full line in a working note, using fields such as path pattern, max-age value, revalidation flag, and validator. For a current entry, an example row could read: hashed stylesheet path, one year, no revalidation, ETag present. For an archived PDF path, the same fields might instead read: PDF folder path, one week, revalidation on, ETag present. Seeing both rows next to each other makes it easier to spot a rule that quietly applies the long immutable lifetime to a page that still needs checking.
You can also compare a draft conflict note with the actual header line before publishing. If a page rule and an asset rule both match the same path, consider rewriting the page rule first and confirming the asset rule no longer matches. A short note such as “page rule wins here” can help teammates follow the choice, though you might decide a comment in the configuration is enough.
Deciding which directive wins is your call. You can keep a small record of that decision so the next person editing the deploy settings sees the same reasoning rather than guessing.
Frequently asked questions
How can I sort my own files before writing any header rule?
Before writing any header rule, you can sort your own files into a simple three-column table: path pattern, how often the content really changes, and which header choice you are leaning toward. For the stylesheet and script bundle with content hashes in their filenames, you might record a one-year freshness lifetime and mark those responses immutable, because a new build produces a new name.
How can I record validator information for each bucket in my table?
Validation deserves its own line in your table. For each bucket, you can record whether the response carries a validator such as an ETag or Last-Modified value, and what a reader's browser should do when the cached copy is older than the lifetime.
How can I compare old and new entries when a diagram or script changes?
When a diagram or script changes, you can compare the old and new entries side by side before publishing. Consider writing the changed line as it would appear after the edit, then keeping the prior line beneath it with a label such as replaced on a given date.
RFC 9111: HTTP Caching . Retrieved 2026-11-21. ↩︎ ↩︎
Cache-Control header - HTTP | MDN . Retrieved 2026-11-21. ↩︎ ↩︎ ↩︎ ↩︎ ↩︎
HTTP caching - HTTP | MDN . Retrieved 2026-11-21. ↩︎ ↩︎