Closed
Description
We want to add preload links for all the files that are on the critical path (dotnet.js, dotnet.runtime.js, dotnet.native.js, dotnet.wasm, boot.js) so the browser can start downloading them eagerly.
In runtime sample we do https://github.com/dotnet/runtime/blob/main/src/mono/sample/wasm/browser-advanced/index.html#L13-L16.
In .NET 9 we have split list of assemblies to "core" (required to started MonoVM) and "others". Preloading core assemblies with lower priority also seems like a good fit.
Implementation plan
- In WebAssembly SDK identify key assets and add preloading properties to endpoints (
rel
,as
,fetchpriority
,crossorigin
,integrity
)- Preload dotnet.js
- Preload boot config
- Preload dotnet.*.js
- Preload dotnet.*.wasm
- Preload core dlls with lower priority
- Based on
StaticWebAssetProjectMode=Default
orOverrideHtmlAssetPlaceholders=true
we can determine whether to use fingerprinted endpoint for dotnet.js and dotnet.boot.js - Based on measurements the best results provided inlining boot config to dotnet.js & preloading dotnet.js
- In StaticWebAssets SDK introduce a new placeholder for preloading meta tags in
OverrideHtmlAssetPlaceholders=true
feature - In AspNetCore runtime (
EndpointHtmlRenderer.WriteComponentHtml
) read preloading properties from endpoints and supply them to the initial response asLink
headers- Do it only for
WebAssembly
render mode, not inAuto
mode
- Do it only for
Additional tasks
- Consider merging boot config into dotnet.js based if preloading measurements prove it's benefitial