Skip to content

MapStaticAssets Cache Control Usage + Documentation #61537

@garrettlondon1

Description

@garrettlondon1

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Image
        // Serve some files unauthenticated
        app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(
                Path.Combine(app.Environment.WebRootPath, "css")),
            RequestPath = "/css"
        });
        
        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();
        app.UseAntiforgery();
        app.MapStaticAssets();

How do you change cache-control header with MapStaticAssets so that files are actually cached by memory cache by browser?

Currently, file is still hitting server after initial load and although it returns 304, isn't the goal to return from memory cache and have the fingerprint change if changed on publish?

Could the documentation clear this up a little? It says Cache-Control is default set to no-cache but doesn't explain how to set the caching strategy in combination with MapStaticAssets

Expected Behavior

Clear documentation on how to handle caching with MapStaticFiles

Its too confusing with WithStaticAssets, MapStaticFiles, UseStaticFiles middleware, etc...

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions