fix: add cache-bust query param to Vite asset URLs for immutable caching#3761
Merged
bartlomieju merged 5 commits intomainfrom Apr 9, 2026
Merged
fix: add cache-bust query param to Vite asset URLs for immutable caching#3761bartlomieju merged 5 commits intomainfrom
bartlomieju merged 5 commits intomainfrom
Conversation
Vite-built assets (JS chunks, CSS) were served with no-cache headers
because the static files middleware only recognized builder-path assets
(under /_fresh/js/{BUILD_ID}/) as immutable.
Add an `immutable` flag to the file snapshot interface. The Vite plugin
marks manifest chunks and CSS as immutable (content-hashed filenames),
while public directory files remain non-immutable. The middleware checks
this flag alongside the existing path and query param checks.
Closes #3282
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
055be3c to
f80b116
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The preact_hooks.ts changes from the initial URL-based approach were accidentally left in the commit. These added ?__frsh_c query params to JS module imports which broke builder-path tests. The immutable flag approach doesn't need any changes to import URLs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The registerStaticFile function in server_entry.ts was dropping the hash and immutable fields when adding files to the snapshot's staticFiles Map. On Windows, this caused server-entry assets to overwrite snapshot entries, losing the immutable flag. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On Windows, path.relative returns backslashes but the registeredPaths Set uses forward slashes from Vite's manifest. This caused every file to be re-registered without the immutable flag, overwriting the original entries from the manifest scan. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
|
Reviewed the diff — this looks good to merge:
|
This was referenced Apr 27, 2026
Merged
bartlomieju
added a commit
that referenced
this pull request
Apr 27, 2026
- Bump `@fresh/core` to `2.3.1` - Bump `@fresh/init` to `2.3.1` - Bump `@fresh/update` to `2.3.1` - Bump `@fresh/plugin-vite` from `1.0.8` to `1.1.0` - Bump `@fresh/plugin-tailwind-v3` from `1.0.1` to `1.1.0` The plugin packages were not published during the 2.3.0 release despite having significant changes merged. Notable fixes in `@fresh/plugin-vite` include immutable caching for Vite-built assets (#3761), CSS modules in layouts (#3764), and multiple `staticDir` support (#3759). Also updates `FRESH_VITE_PLUGIN` version constant in `@fresh/init` so new projects scaffold with the correct plugin version. Closes #3784
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
Cache-Control: no-cache, no-storebecause the static files middleware only recognized builder-path assets (under/_fresh/js/{BUILD_ID}/) as immutableimmutableflag toFileSnapshot,StaticFile, andPendingStaticFileinterfacesimmutable: true(these have content-hashed filenames), while public directory files remain non-immutablefile.immutablealongside the existing path and query param checksCloses #3282
Test plan
vite build - asset cache headers on CSS and JS— fetches CSS and JS asset URLs from a page with islands and verifies they returnCache-Control: public, max-age=31536000, immutable🤖 Generated with Claude Code