From 3b8ac70b7829508bbb929ac9718c14131c666d8c Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Tue, 11 Nov 2025 09:48:55 +0900 Subject: [PATCH] chore: add cache-control response header --- src/Docfx.App/RunServe.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Docfx.App/RunServe.cs b/src/Docfx.App/RunServe.cs index fa14f8d5135..5ef7a3c8a8d 100644 --- a/src/Docfx.App/RunServe.cs +++ b/src/Docfx.App/RunServe.cs @@ -89,6 +89,17 @@ public static IApplicationBuilder UseServe(this WebApplication app, string folde // Fix the issue that .JSON file is 404 when running docfx serve fileServerOptions.StaticFileOptions.ServeUnknownFileTypes = true; + + // Set `Cache-Control` response header. (To avoid browser's default heuristic cache) + fileServerOptions.StaticFileOptions.OnPrepareResponse = ctx => + { + var headers = ctx.Context.Response.GetTypedHeaders(); + headers.CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue + { + MaxAge = TimeSpan.FromSeconds(60), + }; + }; + return app.UseFileServer(fileServerOptions); }