Skip to content

Commit 3b8ac70

Browse files
committed
chore: add cache-control response header
1 parent 0a82923 commit 3b8ac70

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Docfx.App/RunServe.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ public static IApplicationBuilder UseServe(this WebApplication app, string folde
8989

9090
// Fix the issue that .JSON file is 404 when running docfx serve
9191
fileServerOptions.StaticFileOptions.ServeUnknownFileTypes = true;
92+
93+
// Set `Cache-Control` response header. (To avoid browser's default heuristic cache)
94+
fileServerOptions.StaticFileOptions.OnPrepareResponse = ctx =>
95+
{
96+
var headers = ctx.Context.Response.GetTypedHeaders();
97+
headers.CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue
98+
{
99+
MaxAge = TimeSpan.FromSeconds(60),
100+
};
101+
};
102+
92103
return app.UseFileServer(fileServerOptions);
93104
}
94105

0 commit comments

Comments
 (0)