-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
When serving static files, I want to tell the browser how to handle caching, instead of letting it do whatever it pleases.
While StaticFileMiddleware does set some caching headers, "Cache-Control" is not among them.
This is similar to #44153, but I would like to instruct the browser in production that files should not be expected to change for a significant period of time.
Describe the solution you'd like
Originally posted by @Tratcher in #44153
Add
string? CacheControlto StaticFileOptionsSet this to
Cache-Control: max-age=0, must-revalidatein the default host builder for IsDevelopment, but make sure it's easy to override for other environments.
This would allow easily setting the header per environment with only single line of code.
builder.Services.Configure<StaticFileOptions>(builder.Configuration.GetSection("StaticFileOptions")
Additional context
Work-arounds do exist, but are not ideal compared to something integrated.