Improved loading times, improved SEO for lighthouse

This commit is contained in:
2025-10-11 00:10:57 +02:00
parent 4e8adcf1ff
commit 394e5a1631
2 changed files with 26 additions and 9 deletions

View File

@@ -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();