fix: content-hash static assets so CSS updates aren't served stale#49
Merged
Conversation
…hed stale
The stylesheet was linked at the fixed URL /css/style.css, so after a deploy a
player's browser kept serving its cached copy of the old CSS. That's why the
password-field styling fix didn't appear until a hard refresh — the field only
looked right after pressing "Show" because the stale rule matched type="text".
Any future CSS change would hit the same wall.
This enables Spring's content-based resource versioning, so Thymeleaf @{} links
resolve to /css/style-<md5>.css; when the file changes the hash changes, the URL
changes, and the browser fetches the new file immediately. A @SpringBootTest
asserts the rendered login page links the versioned URL rather than the bare
path, guarding against regressions.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Fixes the reported bug where the password field rendered unstyled (white/small) until you pressed "Show" or hard-refreshed. The deployed CSS was correct, but the stylesheet was linked at the fixed path
/css/style.csswith no cache-busting — so browsers kept serving a stale cached copy from before the password-styling fix. Pressing "Show" flips the input totype="text", which the old cached rule happened to match, masking the problem.Fix
Enables Spring's content-based static-resource versioning (
spring.web.resources.chain.strategy.content). Thymeleaf@{/css/style.css}links now resolve to/css/style-<md5>.css; when the file changes, the hash and URL change, and browsers fetch the new file immediately instead of reusing a cached one. This prevents the stale-asset problem for all future CSS/JS changes, not just this one.Test
StaticAssetVersioningTest(@SpringBootTest+MockMvc) renders/loginand asserts the stylesheet is linked via its content-hashed URL, not the bare/css/style.css.Note
Deploying this changes the stylesheet URL, so it also resolves the stale view for anyone currently affected — no hard refresh needed once it's live.
🤖 Generated with Claude Code