From 3a2557c21e81dc76c8880cf5ae81d546d186989f Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Thu, 28 Nov 2024 15:41:32 +0100 Subject: [PATCH] Set cache-control headers for static files to max one week --- HaWeb/Program.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/HaWeb/Program.cs b/HaWeb/Program.cs index 9565f77..b6823b1 100644 --- a/HaWeb/Program.cs +++ b/HaWeb/Program.cs @@ -68,6 +68,14 @@ if (!app.Environment.IsDevelopment()) { } app.UseAuthorization(); -app.UseStaticFiles(); + +var cacheMaxAgeOneWeek = (60 * 60 * 24 * 7).ToString(); +app.UseStaticFiles(new StaticFileOptions { + // Set ETag: + OnPrepareResponse = ctx => { + ctx.Context.Response.Headers.Add("Cache-Control", "public, max-age=" + cacheMaxAgeOneWeek); + }, + ServeUnknownFileTypes = true, +}); app.MapControllers(); app.Run();