Skip to content

Commit 0df9366

Browse files
Don't cache index.html during development (#59340) (#59348)
1 parent c157802 commit 0df9366

File tree

1 file changed

+9
-0
lines changed
  • src/Components/WebAssembly/DevServer/src/Server

1 file changed

+9
-0
lines changed

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.

0 commit comments

Comments
 (0)