-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[Blazor] Add version-based cache busting to dotnet.js import statements #63164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/8.0
Are you sure you want to change the base?
Conversation
Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
dotnet.js
import statement in .NET 8.0Co-authored-by: javiercn <[email protected]>
69bee3a
to
5e56cbc
Compare
@copilot I rebased on top of release/8.0, but now you need to fix the problems |
- Resolved merge conflicts by properly merging cache busting functionality - Applied cache busting query parameter to both loadBootResource call and import statement - Uses ${src}?v=${Date.now()} to append timestamp to existing src path - Maintains backward compatibility and supports custom resource loaders Co-authored-by: javiercn <[email protected]>
Fixed the merge conflicts after the rebase to release/8.0. The cache busting functionality has been properly merged and now correctly applies timestamp query parameters to both the loadBootResource call and the import statement while maintaining compatibility with custom resource loaders. Commit: acd0e32 |
…anipulation with 8.0.19 Co-authored-by: javiercn <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements version-based cache busting for dotnet.js
imports in Blazor WebAssembly applications to prevent browsers from using stale cached versions when the framework has been updated.
Key Changes:
- Adds a static version parameter (
v=8.0.19
) to dotnet.js import URLs - Uses proper URL manipulation with URL and URLSearchParams APIs
- Only adds versioning when no existing version parameter is present
const absoluteSrc = (new URL(src, document.baseURI)).toString(); | ||
const absoluteUrl = new URL(src, document.baseURI); | ||
if (!absoluteUrl.searchParams.has('v')) { | ||
absoluteUrl.searchParams.set('v', '8.0.19'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded version '8.0.19' should be extracted to a constant or configuration value to make it easier to maintain and update across releases.
absoluteUrl.searchParams.set('v', '8.0.19'); | |
absoluteUrl.searchParams.set('v', DOTNET_JS_VERSION); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think dotnet.js
changes with the used runtime pack Nuget and with installed version of the wasm workload.
This would need some MSBuild magic, not just a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a one-time fix to help alleviate the problem for the people currently facing it in 8.0. Given how transient the nature of this problem is (you have to get an old version, then a new version) I don't plan on building any more complex machinery for this.
In fact, since this is already fixed in 9.0 for hosted scenarios and 10.0, I don't necessarily believe we need to do anything more, but since the change is simple, I'm willing to consider this for a patch. I wouldn't do a fix any more complex than this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do it only in case there is no custom loadBootResource
? Can adding a query string parameter break something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry about it, it's very unlikely that a query string breaks anything, but I don't mind commanding our silicon-based coworker to make that change.
This PR adds cache busting functionality to the
dotnet.js
import statements in Blazor WebAssembly applications to ensure browsers don't use stale cached versions when the file has been updated.Changes Made
Modified
/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts
to add version-based cache busting to dotnet.js imports:8.0.19
instead of dynamic timestampsv=8.0.19
if nov
parameter is already presentImplementation Details
new URL(src, document.baseURI)
to properly construct the absolute URLURLSearchParams.has('v')
to check for existing version parametersURLSearchParams.set('v', '8.0.19')
to add version when neededExample
Before:
After:
This ensures each import gets a versioned URL like
_framework/dotnet.js?v=8.0.19
, forcing browsers to bypass cache when dotnet.js has been updated, while respecting any existing version parameters that may have been set by custom loaders.Fixes #63161.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.