In this post, I describe how to lazy load assemblies in a ASP.NET Core Blazor WebAssembly application.

When a Blazor WebAssembly application starts, it first gets all DLLs of the application. So, even if a DLL is used only in a specific page, it is loaded when the app loads. If you want to improve the startup performance, you can defer the loading of some application assemblies until they are required.

Lazy loading assemblies

First, you need to edit the project file (csproj) and add the list of lazy loaded assemblies using <BlazorWebAssemblyLazyLoad>:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
    <UseBlazorWebAssembly>true</UseBlazorWebAssembly>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-preview.8.20414.8" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-preview.8.20414.8" PrivateAssets="all" />
    <PackageReference Include="YamlDotNet" Version="8.1.2" />
  </ItemGroup>

  <ItemGroup>
    <BlazorWebAssemblyLazyLoad Include="YamlDotNet" />
  </ItemGroup>

</Project>

#blazor #asp.net core #webassembly #dotnet #web-development

Lazy load assemblies in a Blazor WebAssembly Application
15.05 GEEK