fix: guarantee unique cache-buster per deploy#96
Merged
antosubash merged 1 commit intomainfrom Apr 8, 2026
Merged
Conversation
Deploying simplemodule-website with
|
| Latest commit: |
6e348ea
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b067adb7.simplemodule-website.pages.dev |
| Branch Preview URL: | https://fix-cache-buster-defaults.simplemodule-website.pages.dev |
The Dockerfile hardcoded `ARG DEPLOY_VERSION=latest`, so every image shipped with `DEPLOYMENT_VERSION=latest` and every asset URL ended in `?v=latest`. InertiaMiddleware.GetVersion()'s assembly-timestamp fallback was masked, the X-Inertia-Version header never changed between deploys, and browsers kept serving cached bundles that referenced chunk hashes no longer on disk — hard 404 on dynamic imports like Home-MQTOkMvb.mjs. Fix: default DEPLOY_VERSION to empty. When unset, GetVersion() derives the version from the entry assembly's last-write timestamp (yyyyMMddHHmmss), which advances on every publish and guarantees cache invalidation with zero configuration. Override with `--build-arg DEPLOY_VERSION=$(git rev-parse --short HEAD)` for deterministic versions if needed. Vendor chunks (/js/vendor/*.js) are intentionally left uncached — they only change when the underlying npm packages change, not per deploy, so a cache buster on them would just force a re-download of ~130 KB of identical bytes every release.
bd3dac6 to
6e348ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two gaps were letting browsers cache stale JS/CSS across deploys, causing the exact symptoms from #94's original bug report to reappear after that PR shipped:
DockerfilehardcodedARG DEPLOY_VERSION=latest, so every image setDEPLOYMENT_VERSION=latestand every asset URL ended in?v=latest.InertiaMiddleware.GetVersion()'s assembly-timestamp fallback was masked, theX-Inertia-Versionheader never changed between deploys, and browsers kept serving cached bundles that referenced chunk hashes no longer on disk — hard 404 on dynamic imports likeHome-MQTOkMvb.mjs.index.htmlreferenced five vendor entries (/js/vendor/react.js,react-dom,react-dom/client,react/jsx-runtime,@inertiajs/react) with no?v=suffix at all, so fresh deploys kept using the browser's cached vendor chunks indefinitely.Changes
Dockerfile: defaultDEPLOY_VERSIONto empty. When unset,InertiaMiddleware.GetVersion()derives the version from the entry assembly's last-write timestamp (yyyyMMddHHmmss), which advances on every publish. Pass--build-arg DEPLOY_VERSION=$(git rev-parse --short HEAD)for deterministic versions if needed.template/SimpleModule.Host/wwwroot/index.html: add?v=<!--DEPLOY_VERSION-->to each importmap entry so they participate in the same replacement pass asapp.jsandapp.css.Test plan
Verified locally with
dotnet run --project template/SimpleModule.Host:<meta name="cache-buster">20260408111445/css/app.css?v=20260408111445/_content/SimpleModule.PageBuilder/simplemodule.pagebuilder.css?v=20260408111445/js/vendor/react.js(+ 4 other vendor entries)?v=20260408111445/js/app.js?v=20260408111445Direct fetches all returned
200with correctContent-Type:/css/app.css→text/css/_content/SimpleModule.PageBuilder/simplemodule.pagebuilder.css→text/css/js/app.js→text/javascript/js/vendor/react.js→text/javascript/_content/SimpleModule.Users/SimpleModule.Users.pages.js→text/javascriptAlso verified via
docker build -t simplemodule:test . && docker run ...that the rendered HTML emits a fresh timestamp instead of the literallateststring.?v=values (no manual--build-argneeded).