{"id":11182,"date":"2025-08-17T21:41:17","date_gmt":"2025-08-17T21:41:17","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=11182"},"modified":"2025-08-17T21:41:17","modified_gmt":"2025-08-17T21:41:17","slug":"lazy-loading-blazor-webassembly-assemblies","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/lazy-loading-blazor-webassembly-assemblies\/","title":{"rendered":"Lazy loading Blazor WebAssembly assemblies"},"content":{"rendered":"<p>We can set our WebAssembly application to lazy load assemblies thus reducing the initial download of files.<\/p>\n<p>For example if you have parts of your application that are rarely used, you could ensure these parts exist within their own (or shared) assembly and then set the project up to lazy load them when required. We simply make these changes to the csproj file<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;ItemGroup&gt;\r\n  &lt;BlazorWebAssemblyLazyLoad Include=&quot;your-assembly.dll&quot; \/&gt;\r\n&lt;\/ItemGroup&gt;\r\n<\/pre>\n<p>We can use the <em>LazyAssemblyLoader<\/em> service to download\/load assemblies as required (don&#8217;t forget to register the LazyAssemblyLoader as a singleton), for example<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n@inject LazyAssemblyLoader AssemblyLoader\r\n\r\n@code {\r\n  private async Task OnNavigateAsync(NavigationContext args)\r\n  {\r\n    try \r\n    { \r\n       if (args.Path = = &quot;{PATH}&quot;) \r\n       { \r\n         var assemblies = await AssemblyLoader.LoadAssembliesAsync( \r\n           new&#x5B;] { {LIST OF ASSEMBLIES} }); } \r\n       } \r\n       catch (Exception ex) \r\n       { \r\n         Logger.LogError(&quot; Error: {Message}&quot;, ex.Message); \r\n       } \r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We can set our WebAssembly application to lazy load assemblies thus reducing the initial download of files. For example if you have parts of your application that are rarely used, you could ensure these parts exist within their own (or shared) assembly and then set the project up to lazy load them when required. We [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[305],"tags":[],"class_list":["post-11182","post","type-post","status-publish","format-standard","hentry","category-blazor"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=11182"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11182\/revisions"}],"predecessor-version":[{"id":11644,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11182\/revisions\/11644"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=11182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=11182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=11182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}