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); }