Skip to content
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

[Blazor WebAssembly standalone] Don't cache index.html during development #59340

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
<_FrameworkStaticWebAssetCandidate Remove="@(_MissingFrameworkStaticWebAssetCandidate)" />
</ItemGroup>

<Message Importance="High" Text="Framework asset '%(_MissingFrameworkStaticWebAssetCandidate.Identity)' could not be found and won't be included in the project." />
<Message
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to the main fix - it was logging a message even when _MissingFrameworkStaticWebAssetCandidate was empty.

Importance="High"
Condition="'@(_MissingFrameworkStaticWebAssetCandidate->Count())' != '0'"
Text="Framework asset '%(_MissingFrameworkStaticWebAssetCandidate.Identity)' could not be found and won't be included in the project." />

<PropertyGroup>
<_FrameworkAssetsPath>$(IntermediateOutputPath)frameworkassets</_FrameworkAssetsPath>
Expand Down
9 changes: 9 additions & 0 deletions src/Components/WebAssembly/DevServer/src/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNetCore.Components.WebAssembly.DevServer.Server;

Expand Down Expand Up @@ -69,6 +70,14 @@ public static void Configure(IApplicationBuilder app, IConfiguration configurati
{
OnPrepareResponse = fileContext =>
{
// Avoid caching index.html during development.
// When hot reload is enabled, a middleware injects a hot reload script into the response HTML.
// We don't want the browser to bypass this injection by using a cached response that doesn't
// contain the injected script. In the future, if script injection is removed in favor of a
// different mechanism, we can delete this comment and the line below it.
// See also: https://github.com/dotnet/aspnetcore/issues/45213
fileContext.Context.Response.Headers[HeaderNames.CacheControl] = "no-store";

if (applyCopHeaders)
{
// Browser multi-threaded runtime requires cross-origin policy headers to enable SharedArrayBuffer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
<_WebViewAssetCandidates Remove="@(_MissingWebViewAssetCandidates)" />
</ItemGroup>

<Message Importance="High" Text="WebView asset '%(_MissingWebViewAssetCandidates.Identity)' could not be found and won't be included in the project." />
<Message
Importance="High"
Condition="'@(_MissingWebViewAssetCandidates->Count())' != '0'"
Text="WebView asset '%(_MissingWebViewAssetCandidates.Identity)' could not be found and won't be included in the project." />

<DefineStaticWebAssets
CandidateAssets="@(_WebViewAssetCandidates)"
Expand Down
Loading