Skip to content

Commit

Permalink
Don't cache index.html during development (#59340)
Browse files Browse the repository at this point in the history
  • Loading branch information
MackinnonBuck authored and github-actions committed Dec 5, 2024
1 parent dc3b208 commit 5468c9b
Showing 1 changed file with 9 additions and 0 deletions.
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 @@ -5,6 +5,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 @@ -65,6 +66,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

0 comments on commit 5468c9b

Please sign in to comment.