Skip to content

[release/9.0] [Blazor WASM standalone] Avoid caching index.html during development #59348

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

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
9 changes: 9 additions & 0 deletions src/Components/WebAssembly/DevServer/src/Server/Startup.cs
Original file line number Diff line number Diff line change
@@ -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;

@@ -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://git.1-hub.cndotnet/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.
Loading