What you'll learn: By the end of this lesson you will be able to name the three places where a front end drifts from its world after a deploy (files, API, caches), explain how content-hashed filenames and an
immutablelifetime make asset caching safe, detect that a tab runs an old build, choose between pinning a tab and asking it to reload, and size the window for which old files must stay online.
Think of a printed menu on every table and a kitchen that changes its dishes overnight. Guests who sit down tomorrow get the new menu; guests still at the table order from the old one, and the kitchen either honours it or does not. A deploy is the same: the new version appears at one moment, but each browser tab is a menu someone is still reading.
The running example is the storefront of the ShopStream grocery marketplace: a single-page app with a product page, a basket and a lazy-loaded delivery-slot step, served as static files through a CDN, calling a JSON API.
The core idea
- A deploy is atomic on the server and gradual in the browser. The files change at one instant; tabs, caches and service workers change when each of them next asks. For a while two versions are alive at once. That mismatch is version skew.
- Make files immutable, and make the pointer to them fresh. Each asset gets a name derived from its content, so a name never refers to two different files and can be cached for a very long time. The HTML that names the assets is the only thing that must be re-checked.
- Skew is managed, not removed. You keep old files online, you detect the mismatch, and you decide per flow whether to reload, wait or stay pinned. The API has to tolerate older clients too.
Where skew appears
| Skew | What the old tab does | Typical symptom |
|---|---|---|
| Files | Requests a lazy chunk or stylesheet that the new deploy deleted | Failed to fetch dynamically imported module, a blank step |
| API | Sends or expects a shape the new server no longer speaks | A 400 on submit, a missing field, a crash while rendering |
| Caches | A CDN, browser cache or service worker still serves the previous shell | "I still see the old price" after a purge, a build you rolled back that returns |
The third is covered by CDN and Edge Caching and Service Worker Lifecycle and Updates. A widely cited article defines version skew as what happens when two or more distributed systems with a dependency between them get deployed; the deployment is not atomic, so they end up at different versions. It names "frontend client skew" as the case where some clients still have the old website loaded.
Cache busting: names that change with content
The idea is old and simple. MDN describes it as the cache-busting pattern: static resources carry a version or hash in their URL and are never modified; when one needs to change, it is replaced by a new resource with a new URL, so caches never reuse the old copy. Webpack's documentation describes the mechanism: [contenthash] adds a hash based on the content of an asset, and when the content changes, the hash changes as well.
Illustration 1: the minimal example
Two builds of the storefront. Only the app code changed between them; the delivery chunk is byte-identical. Run in Node:
import { createHash } from "node:crypto";
const hashed = (name, ext, text) =>
`${name}.${createHash("sha256").update(text).digest("hex").slice(0, 8)}.${ext}`;
const buildA = { app: "render(cart)", delivery: "pickSlot()" };
const buildB = { app: "render(cart, promo)", delivery: "pickSlot()" };
for (const [label, build] of [["build A", buildA], ["build B", buildB]]) {
console.log(label, "->", hashed("app", "js", build.app), hashed("delivery", "js", build.delivery));
}
Output, from running it in Node 26.13.1:
build A -> app.48941d19.js delivery.16626d0f.js
build B -> app.3cb45e54.js delivery.16626d0f.js
The app file got a new name; the delivery chunk kept its name. A browser that already holds delivery.16626d0f.js has nothing to download, and any cache can keep it as long as it likes, because that name can never mean different bytes. Real bundlers hash differently, so this shows the idea, not your build's output.
Webpack's documentation adds a caution: a build with no changes can still produce a new filename, because the entry chunk includes boilerplate (the runtime and manifest), which optimization.runtimeChunk: 'single' splits out. A vendor chunk can also change when module ids change with the resolving order; production mode defaults optimization.moduleIds to 'deterministic'. Check your own bundler's output on two identical builds.
Figure 1. Immutable files, fresh pointer
How to read this: the tab asks for the HTML every time and gets a small answer that either confirms its copy or names new files. The asset boxes are only requested when a name is new, so they can live in every cache for a long time. The CDN holds the files of both builds.
The headers
MDN's guidance for hashed assets is a long lifetime plus immutable:
# /assets/*
Cache-Control: max-age=31536000, immutable
# /index.html
Cache-Control: no-cache
31536000 seconds is 365 days. immutable tells a cache the response will not be updated while it is fresh, which avoids the conditional request a browser would otherwise send on a reload; RFC 8246 says clients should not issue a conditional request during the response's freshness lifetime unless the user forces a reload. For the HTML, no-cache does not mean "do not cache": it lets a cache store the response but requires validation with the origin before each reuse. Vite's documentation gives the reason: without no-cache on the HTML, the old assets stay referenced. HTTP Caching for the Front End explains each directive.
What goes wrong in an open tab
The headers protect a tab that reloads, not one that stays open. That tab still runs build A's JavaScript, which contains build A's lazy chunk names and API call shapes.
Figure 2. The open tab and the server that moved on
How to read this: the tab did nothing wrong and nothing failed. The server's answer carried the build id, which is the cheapest way for a tab to learn it is stale.
The ladder of defences
- Keep old files online. Vite's documentation warns that the hosting service may delete the assets of previous deployments, so an older copy of the site can try to import a deleted chunk.
- Recover from a load error. Vite emits
vite:preloadErrorwhen a dynamic import fails, andevent.preventDefault()stops the error being thrown. Blue-Green and Canary Releases, and Rollbacks shows a reload-once guard. - Detect and tell the tab with a build id (next section).
- Pin the tab so the platform serves its requests from the deployment that served its page.
- Make the API tolerant. Servers never introduce new required fields until all clients are updated, and clients never require recently introduced server changes (see API Contract Evolution for Clients).
The same skew article calls HTML skew extremely difficult to reason about and concludes that the only way to manage it is to make sure it never occurs, which is why the HTML is the file you never let go stale.
Detecting skew
A build id (a commit hash or a release number) is written into the HTML at build time and sent on API responses in a header such as x-build-id (a name you choose, not a standard). The tab compares the two. Frameworks do the same: when Next.js has a deploymentId configured it appends ?dpl=<deploymentId> to static asset URLs, adds an x-deployment-id header to client-side navigation requests, adds an x-nextjs-deployment-id header to navigation responses, and injects a data-dpl-id attribute on the <html> element. When the client sees a mismatch it makes a hard navigation (a full page reload) instead of a client-side one.
Illustration 2: the realistic example
Detecting is easy; deciding is the design work. Reloading discards typed input and can interrupt a payment. This pure function takes the two ids and what the tab is doing. Run in Node:
function skewAction({ loaded, seen, formDirty, criticalFlow }) {
if (seen === loaded) return "none";
if (criticalFlow) return "finish the flow on the old build, then offer a reload";
if (formDirty) return "show a banner: reload when ready (do not reload now)";
return "reload at the next navigation";
}
const cases = [
{ loaded: "b7", seen: "b7", formDirty: false, criticalFlow: false },
{ loaded: "b7", seen: "b8", formDirty: false, criticalFlow: false },
{ loaded: "b7", seen: "b8", formDirty: true, criticalFlow: false },
{ loaded: "b7", seen: "b8", formDirty: false, criticalFlow: true },
];
for (const c of cases) {
const input = `loaded=${c.loaded} seen=${c.seen} dirty=${c.formDirty} critical=${c.criticalFlow}`;
console.log(input.padEnd(48), "->", skewAction(c));
}
Output, from running it in Node 26.13.1:
loaded=b7 seen=b7 dirty=false critical=false -> none
loaded=b7 seen=b8 dirty=false critical=false -> reload at the next navigation
loaded=b7 seen=b8 dirty=true critical=false -> show a banner: reload when ready (do not reload now)
loaded=b7 seen=b8 dirty=false critical=true -> finish the flow on the old build, then offer a reload
Reloading at the next navigation is the cheap default: the user is moving anyway, so a full load costs little extra.
Figure 3. What a tab does on a mismatch
(payment)"} B -->|"yes"| C["Finish on old build,
then offer reload"] B -->|"no"| D{"Unsaved input?"} D -->|"yes"| E["Banner: reload when ready"] D -->|"no"| F["Reload at next navigation"]
How to read this: the order of the questions matters. The riskiest situation (a payment) is asked first because it forbids the action the later branches allow.
Pinning a tab to its version
Instead of asking the tab to move, you can keep it where it is. Vercel's Skew Protection implements version locking: the framework includes the deployment id in framework-managed requests (static assets, client-side navigations and Server Actions, prefetches), and the platform routes them to the deployment that served the initial page. For some frameworks a __vdpl cookie carries the id, which also pins your own fetch() calls.
Know the limits, which Vercel's page states plainly:
- It does not pin full-page navigations. A hard refresh or a link opened in a new tab gets the latest production deployment.
- It has a maximum age, measured from when the deployment was created. The default is 12 hours on Pro and one day on Enterprise. A request for a deployment older than that, or one that no longer exists, is served by the deployment currently assigned to the domain.
- With Next.js and Astro, requests that do not carry the id (for example your own
fetch()calls) go to the latest deployment.
Vercel advises a maximum age that covers the time between deployments plus your longest session. On a plain bucket and CDN there is no such feature; the equivalent is to keep old builds in place.
Illustration 3: a failure, a missing file that answers 200
A common host setting rewrites any unknown path to the HTML shell, so a single-page app can handle client-side routes. If that rule also catches a deleted chunk, the request returns the shell instead of 404, and the browser tries to run HTML as JavaScript. This toy host (not your host) reproduces the pattern; the content-type check is the guard. Run in Node:
import { createServer } from "node:http";
const files = { "/assets/app.b2c4d6e8.js": "export const ok = true;\n" };
const server = createServer((req, res) => {
const body = files[req.url];
if (body) {
res.writeHead(200, { "content-type": "text/javascript" });
res.end(body);
} else {
res.writeHead(200, { "content-type": "text/html" }); // the fallback rule
res.end("<!doctype html><title>shell</title>");
}
});
await new Promise((r) => server.listen(0, "127.0.0.1", r));
const base = `http://127.0.0.1:${server.address().port}`;
for (const path of ["/assets/app.b2c4d6e8.js", "/assets/delivery.a1b2c3d4.js"]) {
const res = await fetch(base + path);
const type = res.headers.get("content-type");
const usable = res.ok && type.startsWith("text/javascript");
console.log(path.padEnd(30), res.status, type.padEnd(16), usable ? "usable" : "reject: not JavaScript");
}
server.close();
Output, from running it in Node 26.13.1:
/assets/app.b2c4d6e8.js 200 text/javascript usable
/assets/delivery.a1b2c3d4.js 200 text/html reject: not JavaScript
Status 200 for a file that does not exist hides the problem from the CDN's error metrics and from any alert keyed on 404 responses. Configure the host to return 404 for paths under the assets folder, and keep the fallback for routes only.
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| Keep old builds online | Open tabs keep working | Storage, and old code with known bugs stays reachable |
| Reload on mismatch | Every tab converges on one version | Lost input, interrupted flows |
| Banner and user-chosen reload | No surprise | Tabs stay stale for hours |
| Version pinning by the platform | No reload, no new code | Lock-in, a maximum age, full-page loads not pinned |
Content-hashed names, immutable |
Fewer requests, no purges | A mistake in hashing or headers is cached for a year |
Build it
There is no lab for this lesson. The three Node snippets ran as shown; the headers and platform features come from documentation and were not tested against a real CDN or host.
The other side of this topic
The back-end view, rolling a service out next to its clients, is the Backend lesson on deployment strategies (blue-green, canary, rolling). A planned lesson on shipping front-end changes safely with the backend combines both views.
In practice: the delivery-slot step after a deploy
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
ShopStream's storefront deploys several times a day, and shoppers keep the basket tab open for a long time. After each deploy, support hears that "choose a delivery slot does nothing" from shoppers who have not reloaded.
Starting architecture
Figure 4. Deploys that delete the previous build
How to read this: the warning boxes are where the problem lives. The tab asks for a chunk name that only build A knew, and the CDN no longer has it.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Reload automatically on a chunk error | The delivery step recovers | Lost input mid-checkout | A loop if the chunk is missing for another reason |
| Keep the last N builds online, and send a build id | Old tabs work; new ones learn they are stale | Storage; a header and a banner | N too small for long sessions |
| Platform version pinning | No code | A paid plan on some platforms; a maximum age | Pinning does not cover full-page loads |
The decision
| Field | Decision record |
|---|---|
| Context | Deploys delete the previous build, so lazy chunks vanish under open tabs. |
| Decision | Keep each build's files for a retention window longer than the longest session plus the interval between deploys, add no-cache to the HTML and immutable to hashed files, send an x-build-id response header, and show a banner (never an automatic reload) when it differs during checkout. |
| Consequences, good | Open tabs keep working; stale tabs are told, once. |
| Consequences, bad | More storage; one more header to keep in step with the build. |
| Revisit when | Sessions get longer than the retention window, or a pinning feature becomes available. |
Rollout and verification
- Prove the window: after a deploy, list the previous two builds' files on the CDN.
- Test the headers on the HTML and on a hashed asset, and a made-up asset path (expect 404, not the shell).
- Simulate a stale tab: load the old build, deploy, then trigger the delivery step and the banner.
The 2 a.m. failure
A deploy at night coincides with a retention job that removes builds older than one deploy. Morning shoppers see a blank delivery step and the error count for lazy imports rises.
First three checks: (1) request a chunk name from the previous build and look at the status and content type; (2) check the retention job's rule against the deploy interval; (3) check whether the error handler reloads in a loop. Mitigation: restore the previous build's files. Follow-up: make retention depend on age, not on count, and alert on lazy-import failures.
Architect's notes
- Version the pointer, not the files. Immutable files can be cached for a year; only the HTML and the build-id source change in place.
- Choose the retention window from the longest session, not from the deploy frequency, and write the number down.
- Treat reload as a user-affecting action. Decide per flow, as in Figure 3.
- Keep the API tolerant first. Detection and pinning only buy time; a required field added too early breaks every old tab.
Common mistakes
- Caching the HTML for hours, so no new deploy is ever seen.
- Using
immutableon files whose names do not change with their content. - Deleting the previous build as the last step of a deploy.
- Reloading automatically in the middle of a payment, or in a loop.
- Adding a required API field in the same release that starts using it.
Key takeaways
- A deploy is atomic on the server and gradual in every tab, cache and service worker; that gap is version skew.
- Content-hashed names let files be cached for a year; the HTML must be revalidated.
- Old builds must stay online longer than the longest session plus the deploy interval.
- A build id in the HTML and in API responses lets a tab notice it is stale; a policy decides what to do.
- Platform pinning avoids reloads but has a maximum age and does not cover full-page loads.
Practice exercises
- Compute the retention window for a store that deploys three times a day and whose longest basket session is a working day. What changes if sessions can last a week?
- Write the headers for
/index.html,/assets/app.<hash>.jsand/service-worker.js, and justify each. - Extend
skewActionwith a rule for a tab that is in the background. - A deploy adds a required field to the order request. In what order must server and client ship so an old tab still works?
Related reading
In this course:
- CI/CD for Front Ends: the deploy order that puts assets before the HTML.
- HTTP Caching for the Front End: freshness, validation and
Cache-Control. - CDN and Edge Caching: purge versus new URLs.
- Blue-Green and Canary Releases, and Rollbacks: releasing to part of the traffic and undoing a release.
- Service Worker Lifecycle and Updates: the cache that can keep a client on the old shell.
- API Contract Evolution for Clients: tolerant readers and rollback windows.
Official documentation
- Industrial Empathy: Version skew: the definition, HTML skew and the mitigation strategies.
- Vite: Building for production: deleted chunks,
vite:preloadErrorandno-cacheon the HTML. - Vercel: Skew Protection: version locking, what it pins and its maximum age.
- Next.js: deploymentId: deployment ids and mismatch handling.
- MDN: Cache-Control and RFC 8246: HTTP Immutable Responses: the cache-busting pattern and
immutable. - webpack: Caching: content hashes, runtime and vendor chunks, module ids.