Skip to content

Instantly share code, notes, and snippets.

@csharpfritz
Last active February 22, 2024 15:43
Show Gist options
  • Save csharpfritz/582b1b408d1b5480e8eac18a27898173 to your computer and use it in GitHub Desktop.
Save csharpfritz/582b1b408d1b5480e8eac18a27898173 to your computer and use it in GitHub Desktop.
Cache control header configuration for the C# in the cards website
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