Skip to content

Feature Request: Cache-Control Header For Static Files #64138

@EmperorArthur

Description

@EmperorArthur

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? CacheControl to StaticFileOptions

  • Set this to Cache-Control: max-age=0, must-revalidate in 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-static-files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions