
Lazy loading reduces the initial download size of a Blazor WASM app by deferring non-essential assemblies until they are actually needed.
<ItemGroup>
<BlazorWebAssemblyLazyLoad Include="MyApp.AdminFeatures.dll" />
</ItemGroup><Router AppAssembly="@typeof(App).Assembly"
OnNavigateAsync="OnNavigateAsync">
@code {
[Inject] private LazyAssemblyLoader AssemblyLoader { get; set; } = default!;
private async Task OnNavigateAsync(NavigationContext context)
{
if (context.Path.StartsWith("admin"))
{
await AssemblyLoader.LoadAssembliesAsync(new[]
{
"MyApp.AdminFeatures.dll"
});
}
}
}Lazy load large, rarely-used features such as admin panels and reporting tools. Keep the core app shell small for fast first load.
Reference:
TaskLoco™ — The Sticky Note GOAT