From 394e5a163156e175bffa476b0cfd6dcea3a4df56 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sat, 11 Oct 2025 00:10:57 +0200 Subject: [PATCH] Improved loading times, improved SEO for lighthouse --- src/Program.cs | 23 +++++++++++++++++++---- src/Views/Shared/_Layout.cshtml | 12 +++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 0dad9d7..9c35a95 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -48,8 +48,8 @@ builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSc builder.Services.AddResponseCompression(options => { options.EnableForHttps = true; - options.MimeTypes = new[] - { + options.MimeTypes = + [ "text/plain", "text/css", "application/javascript", @@ -58,7 +58,7 @@ builder.Services.AddResponseCompression(options => "text/xml", "application/json", "image/svg+xml" - }; + ]; }); var app = builder.Build(); @@ -89,7 +89,22 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } -app.UseStaticFiles(); +app.UseStaticFiles(new StaticFileOptions +{ + OnPrepareResponse = ctx => + { + string requestPath = ctx.Context.Request.Path.ToString(); + if (requestPath.EndsWith(".css") || requestPath.EndsWith(".js")) + { + ctx.Context.Response.GetTypedHeaders().CacheControl = + new Microsoft.Net.Http.Headers.CacheControlHeaderValue() + { + Public = true, + MaxAge = TimeSpan.FromDays(365) + }; + } + } +}); app.UseRouting(); app.UseAuthorization(); app.UseResponseCompression(); diff --git a/src/Views/Shared/_Layout.cshtml b/src/Views/Shared/_Layout.cshtml index 857088e..6ca4965 100644 --- a/src/Views/Shared/_Layout.cshtml +++ b/src/Views/Shared/_Layout.cshtml @@ -4,15 +4,17 @@ + @ViewData["Title"] - Berufsschule_HAM - @* *@ + @* *@ - - + @* *@ + + @@ -71,10 +73,10 @@ © 2025 - Berufsschule_HAM - @* *@ + @* *@ - @* *@ + @* *@