Skip to content

Commit d92fad8

Browse files
Don't cache index.html during development (#59340) (#59349)
Co-authored-by: Mackinnon Buck <mackinnon.buck@gmail.com>
1 parent 65bde51 commit d92fad8

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
@@ -5,6 +5,7 @@
55
using Microsoft.AspNetCore.Http;
66
using Microsoft.Extensions.Configuration;
77
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Net.Http.Headers;
89

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

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

0 commit comments

Comments
 (0)