[release/10.0] Add cache setting to asset definition, use "force-cache" for fingerprinted assets#122442
Conversation
non-cached asset loads
… It directly maps to fetchOptions.cache
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
There was a problem hiding this comment.
Pull request overview
This PR backports a performance improvement for WebAssembly applications by adding cache control settings to asset definitions. The change uses "force-cache" for fingerprinted assets to enable browser-level caching, significantly improving startup performance on subsequent loads.
Key changes:
- Added
cacheproperty to all fingerprinted asset types (WasmAsset, AssemblyAsset, PdbAsset, SymbolsAsset, VfsAsset, IcuAsset, GeneralAsset) - Implemented logic to set cache to "force-cache" for fingerprinted assets and null for non-fingerprinted assets
- Updated both C# (build-time) and TypeScript (runtime) code to handle the new cache property
Reviewed changes
Copilot reviewed 27 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs | Added cache property to asset classes (WasmAsset, GeneralAsset, VfsAsset, SymbolsAsset) for storing cache control settings |
| src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs | Implemented GetCacheControl helper and updated asset mapping to set cache property based on fingerprinting status |
| src/mono/browser/runtime/types/internal.ts | Updated AssetEntryInternal to use cache?: RequestCache instead of noCache?: boolean |
| src/mono/browser/runtime/types/index.ts | Added cache?: RequestCache property to TypeScript asset type definitions |
| src/mono/browser/runtime/loader/assets.ts | Updated fetch logic to use asset.cache when specified, maintaining backward compatibility |
| src/mono/browser/runtime/dotnet.d.ts | Updated public TypeScript definitions to match internal types |
| src/mono/wasm/Wasm.Build.Tests/Blazor/AssetCachingTests.cs | Added comprehensive test verifying cache behavior with and without fingerprinting |
| src/mono/wasm/Wasm.Build.Tests/BrowserStructures/TestAsset.cs | Registered new BlazorWebWasm test asset |
| src/mono/wasm/Wasm.Build.Tests/BrowserStructures/RunOptions.cs | Fixed whitespace formatting |
| src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTestsBase.cs | Refactored to extract BrowserRun method and added projectDir parameter support |
| src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs | Added optional projectDir parameter to GetBuildPaths |
| src/mono/wasm/Wasm.Build.Tests/Common/ToolCommand.cs | Improved error handling for process start failures |
| src/mono/wasm/testassets/BlazorWebWasm/* | Added complete BlazorWebWasm test project for integration testing |
| eng/testing/scenarios/BuildWasmAppsJobsList.txt | Added AssetCachingTests to test job list |
|
/ba-g WasmBuildTests failure is unrelated. The test passed on linux https://helix.dot.net/api/jobs/3cffe909-0716-43b4-bfda-c007bbd41fcd/workitems/Workloads-ST-Wasm.Build.Tests.Blazor.AssetCachingTests?api-version=2019-06-17 |
Backport of #122101 to release/10.0 to fix dotnet/aspnetcore#64009
Customer Impact
The issue significantly effects startup time of every WebAssembly based application.
Regression
Caused by #114901
Testing
Manual testing of Blazor WebAssembly standalone, Blazor Web with WebAssembly & Auto interactivity, with Chromium-based, Firefox and Safari.
Automated test.
Risk
Low. We are changing both built-time generator and runtime part reading the values. Thanks to fingerprinting there isn't a room for some staleness of one part. The change is scoped and in case it won't work in some scenario, the workaround is still possible.