Blazor WASM: Decouple EntrypointInvoker and DefaultWebAssemblyJSRuntime from WebAssembly.dll
See original GitHub issueBy decoupling and/or simply exposing these 2 internal classes, we can enable more aggressive trimming in minimalistic WASM apps. This results in a reduction of 15+ dll dependencies that WebAssembly.dll brings with it, improving page load performance for minimalistic wasm applications.
Summary
Currently (in version 5.0.1), one must either exclude Microsoft.AspNetCore.Components.WebAssembly.dll from linking or at least reference the Microsoft.AspNetCore.Components.WebAssembly.Hosting class to produce a viable build that executes and interops with Javascript.
Motivation and goals
Microsoft.AspNetCore.Components.WebAssembly.dll is currently a monolith that
- is required to successfully produce a build because it produces JS files.
- is explicitly required by blazor.webassembly.js
- contains the mostly standalone classes EntrypointInvoker and DefaultWebAssemblyJSRuntime, which are required for JS interop
- contains additional services and dependencies to support the full Blazor framework but that are not relevant for a simple Hello World or minimalistic application.
This is a relatively simple change that would help break the WebAssembly.dll monolith.
In scope
- This only concerns trimming of WebAssembly.dll
- A simple Hello World console application (or equivalent) should not result in the loading of Microsoft.Extensions.* and Microsoft.AspNetCore.* dlls or other unnecessary dlls.
Out of scope
- This does not concern trimming of other Blazor or .Net dependencies.
Risks / unknowns
This change does not break functionality. Some documentation for proper use would be needed.
Examples
A project file to support the minimalistic build would look like this.
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<TrimmerRootAssembly Include="[NEW MINIMAL DEPENDENCY]" />
</ItemGroup>
</Project>
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
@ejhg Thanks for being considerate!
@danroth27 Ping in case you want to continue digging into feasibility/interest for this.
@captainsafia @javiercn Thank you for giving consideration to this proposal. I don’t want to increase your backlog size. I can write my own interop layer anyways, so this is not a blocker for me. I just thought this would be good design feedback to give y’all.
I’ll close this ticket so it doesn’t create unnecessary backlog. Thanks again.