The site sits behind a CDN and shipped static assets with no Cache-Control and no versioning, so browsers/CDN kept serving stale css/js after a deploy (the "design didn't change" symptom). - HTML responses now send Cache-Control: no-cache, no-store, must-revalidate so the page itself is always revalidated. - Static assets get a long cache and are fingerprinted via asp-append-version (/css/site.css?v=<contenthash>), so they bust automatically on every change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+23
-1
@@ -50,7 +50,29 @@ using (var scope = app.Services.CreateScope())
|
||||
}
|
||||
|
||||
app.UseStatusCodePagesWithReExecute("/Error/{0}");
|
||||
app.UseStaticFiles();
|
||||
|
||||
// HTML pages must never be cached by the browser or CDN, so a new deploy is
|
||||
// visible immediately. Static assets are fingerprinted via asp-append-version
|
||||
// (?v=hash), so they can be cached aggressively and bust automatically.
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
context.Response.OnStarting(() =>
|
||||
{
|
||||
if (context.Response.ContentType?.Contains("text/html", StringComparison.OrdinalIgnoreCase) == true)
|
||||
{
|
||||
context.Response.Headers.CacheControl = "no-cache, no-store, must-revalidate";
|
||||
context.Response.Headers.Pragma = "no-cache";
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
await next();
|
||||
});
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
OnPrepareResponse = ctx =>
|
||||
ctx.Context.Response.Headers.CacheControl = "public, max-age=31536000"
|
||||
});
|
||||
|
||||
// Serve uploaded files from /data/uploads under /uploads/*
|
||||
var uploadsPath = Path.Combine(dataDir, "uploads");
|
||||
|
||||
Reference in New Issue
Block a user