Skip to content

Vite asset retention

An atomic release symlink switch does not protect browsers still using the previous build: later chunk requests use the same /js/dist/ URL prefix.

bin/pre-deploy runs bin/retain-vite-assets CANDIDATE LIVE after the client build, before activation. Under the existing deployment lock it copies public client output from both builds into data/vite-assets/js/dist/. Nginx's infra configuration serves the current build first and falls back to this archive. Manifests and hidden paths are excluded; SSR and worker output are not archived. Files are published by atomic rename and conflicting contents at an existing asset path fail deployment rather than overwrite an immutable asset.

File mtimes in the archive track the last deployment needing each asset. Each publication refreshes both outgoing and incoming builds, then deletes assets unused for more than 30 days. Thus the outgoing build gets a full 30-day grace period, even after a long time without deployments. Collection runs on deploy, not a timer; no deployments means no collection. Release-directory cleanup is independent of this archive. Leave the archive intact during routine cleanup.

Rollout and limits

The dash and infra PRs may be deployed in either order; both are needed for protection. Infra falls back only when an asset is missing from the current build, so an absent archive does not break current assets. The hook lives in pre-deploy to run even when the first rollout is driven by an older deployer; that deployer's no-argument call defaults to the standard ../public_html live path. New deployers pass the live path explicitly.

Only the outgoing and incoming builds are seeded. Already-removed older builds cannot be recovered. Tabs more than 30 days behind can still encounter missing chunks; nothing forces a reload or discards unsaved forms. This protects static assets, not compatibility of old clients with changed backend APIs. Staging keeps its existing Vite routing; the nginx fallback is production-only.

Focused local tests:

python3 bin/tests/test-retain-vite-assets.py
bash -n bin/deploy bin/pre-deploy

The infra repository has a companion real-nginx test that evaluates both production hosts and checks archive fallback, missing files and private paths.