dotnet/AspNetCore.Docs

MapStaticAssets optimized for serving the assets that your app has knowledge of at build and publish time.

Rick-Anderson opened this issue · 0 comments

Description

see https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/preview5/aspnetcore.md

MapStaticAssets works by combining work done at build or publish time to gather information about all the static web assets in your app with a runtime library that is capable of processing that information and using it to better serve the files to the browser.

MapStaticAssets can replace UseStaticFiles in most situations. However, it's optimized for serving the assets that your app has knowledge of at build and publish time. This means that if your app serves assets from other locations on disk, or embedded resources, etc. then using UseStaticFiles is still the right choice.

What are the things that MapStaticAssets does that UseStaticFiles doesn't?

Build and publish time compression for all the assets. Uncompressed static web assets are precompressed using gzip as part of the build and then also with brotli during publish to reduce the download size.

Content based ETags. The Etags for each resource are setup to be the Base64 encoded string of the SHA-256 hash of the content. This ensures that the browser doesn't have to download the file again unless its contents change.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-9.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/static-files.md

Document ID

3fec6e08-fc99-7a5c-796f-3f2347cad891

Article author

@Rick-Anderson


Associated WorkItem - 343311