-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[release/8.0] [Blazor WASM standalone] Avoid caching index.html
during development
#59349
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
Merged
Conversation
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
index.html
during developmentindex.html
during development
mkArtakMSFT
approved these changes
Jan 9, 2025
This was referenced Jul 21, 2025
Closed
Closed
Open
This was referenced Aug 19, 2025
Open
Merged
Closed
Open
Closed
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-blazor
Includes: Blazor, Razor Components
feature-blazor-wasm
This issue is related to and / or impacts Blazor WebAssembly
feature-hot-reload
This issue is related to the Hot Reload feaature
pending-ci-rerun
When assigned to a PR indicates that the CI checks should be rerun
Servicing-approved
Shiproom has approved the issue
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.
Avoid caching
index.html
during developmentBackport of #59340
Fixes an issue where running a Blazor WebAssembly standalone app with hot reload enabled doesn't work if the app had been previously run with hot reload disabled.
Description
Background
The
Microsoft.AspNetCore.Components.WebAssembly.DevServer
package provides a server for running Blazor WebAssembly standalone apps in development, and it's what gets used by default in new Blazor WebAssembly standalone projects. One of its responsibilities is serving static files, and this includes the app'sindex.html
.Hot reload functionality depends on an additional
<script />
element being dynamically injected into the response forindex.html
. A development-only middleware provides this behavior.The problem
The development server was serving
index.html
with aCache-Control
header that allowed the browser to cache the response. This meant that if the app was initially run with hot reload disabled, the browser would cache a version ofindex.html
without the injected script. After enabling hot reload, the server would not detect that the cachedindex.html
was invalid, because the file on disk had not changed. As a result, the hot reload script injection middleware would be skipped, and the cached response (without the injected script) would be used. This prevented any hot reload functionality from working.The fix
The fix is simple: change the development server to serve
index.html
with aCache-Control: no-store
header, which prevents the browser from caching the response. This always gives the script injection middleware a chance to inject the hot reload script.Fixes #59276
Customer Impact
Customers relying on the dotnet CLI to run their Blazor WebAssembly standalone app are very likely to encounter this issue. The problem can be reproduced by first running the app using
dotnet run
, then subsequently withdotnet watch
. While less common, the bug can also be reproduced in Visual Studio by explicitly disabling hot reload, running the app, then re-enabling hot reload.Workarounds do exist:
index.html
so that the server recognizes that the file has changedHowever, the user may not be aware of these workarounds, and being forced to manually clear the browser cache creates a frustrating development experience.
Note
Only Blazor WebAssembly standalone apps are affected. The bug does not reproduce on other types of Blazor apps (Web, Server, Hybrid).
Regression?
This bug has existed since .NET 6, and possibly earlier than that.
Risk
The change is small and only impacts how the
index.html
file is served during development.Verification
Packaging changes reviewed?