Skip to content

Commit 7a5e55e

Browse files
Don't cache index.html during development (#59340)
1 parent 74cdf38 commit 7a5e55e

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Assets/build/Microsoft.AspNetCore.App.Internal.Assets.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
<_FrameworkStaticWebAssetCandidate Remove="@(_MissingFrameworkStaticWebAssetCandidate)" />
4141
</ItemGroup>
4242

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

4548
<PropertyGroup>
4649
<_FrameworkAssetsPath>$(IntermediateOutputPath)frameworkassets</_FrameworkAssetsPath>

src/Components/WebAssembly/DevServer/src/Server/Startup.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Http;
77
using Microsoft.Extensions.Configuration;
88
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Net.Http.Headers;
910

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

@@ -69,6 +70,14 @@ public static void Configure(IApplicationBuilder app, IConfiguration configurati
6970
{
7071
OnPrepareResponse = fileContext =>
7172
{
73+
// Avoid caching index.html during development.
74+
// When hot reload is enabled, a middleware injects a hot reload script into the response HTML.
75+
// We don't want the browser to bypass this injection by using a cached response that doesn't
76+
// contain the injected script. In the future, if script injection is removed in favor of a
77+
// different mechanism, we can delete this comment and the line below it.
78+
// See also: https://github.com/dotnet/aspnetcore/issues/45213
79+
fileContext.Context.Response.Headers[HeaderNames.CacheControl] = "no-store";
80+
7281
if (applyCopHeaders)
7382
{
7483
// Browser multi-threaded runtime requires cross-origin policy headers to enable SharedArrayBuffer.

src/Components/WebView/WebView/src/build/Microsoft.AspNetCore.Components.WebView.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
<_WebViewAssetCandidates Remove="@(_MissingWebViewAssetCandidates)" />
3030
</ItemGroup>
3131

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

3437
<DefineStaticWebAssets
3538
CandidateAssets="@(_WebViewAssetCandidates)"

0 commit comments

Comments
 (0)