Skip to content

Preload Blazor WebAssembly resources to improve startup time #58875

Closed
@mkArtakMSFT

Description

@mkArtakMSFT

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 or OverrideHtmlAssetPlaceholders=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 as Link headers
    • Do it only for WebAssembly render mode, not in Auto mode

Additional tasks

  • Consider merging boot config into dotnet.js based if preloading measurements prove it's benefitial

Metadata

Metadata

Assignees

Labels

PerfPriority:1Work that is critical for the release, but we could probably ship withoutarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblytriaged

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions