Last active
February 22, 2024 15:43
-
-
Save csharpfritz/582b1b408d1b5480e8eac18a27898173 to your computer and use it in GitHub Desktop.
Cache control header configuration for the C# in the cards website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseStaticFiles(new StaticFileOptions() | |
{ | |
OnPrepareResponse = | |
r => { | |
string path = r.File.PhysicalPath; | |
if (path.EndsWith(".css") || path.EndsWith(".js") || | |
path.EndsWith(".gif") || path.EndsWith(".jpg") || | |
path.EndsWith(".png") || path.EndsWith(".svg") || path.EndsWith(".webp")) | |
{ | |
TimeSpan maxAge = new TimeSpan(370, 0, 0, 0); | |
r.Context.Response.Headers.Append("Cache-Control", "max-age=" + maxAge.TotalSeconds.ToString("0")); | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment