PlatformPlatform icon indicating copy to clipboard operation
PlatformPlatform copied to clipboard

Add cache control for serving WebApp static files

Open raix opened this issue 4 months ago • 0 comments

One of the Lighthouse findings relates to static files not being aggressively cached in the WebApp Middleware pipeline.

Currently all JavaScript bundles are hashed using "real content hash" enabling invalidation, images stored in the public folder will have to be "manually" invalidated e.g. by renaming (in future releases images will also be applied the real content hash)

Image

Reference:

app.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        ctx.Context.Response.Headers.Append(
             "Cache-Control", $"public, max-age={TimeSpan.FromDays(365).Seconds}");
    }
});

raix avatar Mar 04 '24 10:03 raix