<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blzor tips &#8211; ASP.NET Hosting Reviews and Guides</title>
	<atom:link href="https://topreviewhostingasp.net/tag/blzor-tips/feed/" rel="self" type="application/rss+xml" />
	<link>https://topreviewhostingasp.net</link>
	<description>Help you to find best ASP.NET Core Hosting</description>
	<lastBuildDate>Fri, 16 Jun 2023 08:08:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://topreviewhostingasp.net/wp-content/uploads/2017/01/cropped-trhaico-32x32.png</url>
	<title>blzor tips &#8211; ASP.NET Hosting Reviews and Guides</title>
	<link>https://topreviewhostingasp.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How Lazyloading Works to Increase Your Blazor Performance?</title>
		<link>https://topreviewhostingasp.net/implement-lazyloading-increase-blazor-website-performance/</link>
					<comments>https://topreviewhostingasp.net/implement-lazyloading-increase-blazor-website-performance/#respond</comments>
		
		<dc:creator><![CDATA[Jacques Hunt]]></dc:creator>
		<pubDate>Fri, 16 Jun 2023 08:08:55 +0000</pubDate>
				<category><![CDATA[Hosting Tips]]></category>
		<category><![CDATA[blazor]]></category>
		<category><![CDATA[blazor performance]]></category>
		<category><![CDATA[blazor tutorial]]></category>
		<category><![CDATA[blzor tips]]></category>
		<category><![CDATA[implement lazyloading]]></category>
		<category><![CDATA[increase blazor speed]]></category>
		<category><![CDATA[lazyloading blazor]]></category>
		<guid isPermaLink="false">https://topreviewhostingasp.net/?p=3575</guid>

					<description><![CDATA[In this article, we&#8217;ll examine how to implement lazy loading using Blazor WebAssembly. We can speed up the startup of our Blazor WebAssembly application by delaying the download of resources we don&#8217;t currently require. For instance, downloading all the files pertaining to products, authentication, and other things is useless if we have a large Blazor [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article, we&#8217;ll examine how to implement lazy loading using Blazor WebAssembly. We can speed up the startup of our Blazor WebAssembly application by delaying the download of resources we don&#8217;t currently require. For instance, downloading all the files pertaining to products, authentication, and other things is useless if we have a large Blazor WebAssembly application and our users only want to view the home or contact pages. The program will only download these resources if the user specifically requests them when lazy loading is enabled.</p>
<h2>Setup Blazor WASM Project</h2>
<p>Open the Visual Studio and search for Blazor App. Click on the Next button,</p>
<p><img fetchpriority="high" decoding="async" class=" wp-image-3576 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-min.jpg" alt="" width="604" height="316" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-min.jpg 742w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-min-300x157.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-min-50x26.jpg 50w" sizes="(max-width: 604px) 100vw, 604px" /></p>
<p>Define the project name, path, and solution name. Click on the Create button,</p>
<p><img decoding="async" class=" wp-image-3577 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/project-min.jpg" alt="" width="528" height="359" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/project-min.jpg 666w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/project-min-300x204.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/project-min-50x34.jpg 50w" sizes="(max-width: 528px) 100vw, 528px" /></p>
<p>After that a new window will pop up to choose the target framework (<strong>.Net 6.0</strong>) from the dropdown and make sure to select the Blazor server App and in the Advanced section &#8220;<em>Configure the Https</em>&#8221; is checked.</p>
<p><img decoding="async" class="wp-image-3578 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-setup-min.jpg" alt="" width="648" height="421" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-setup-min.jpg 850w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-setup-min-300x195.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-setup-min-768x499.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-setup-min-50x32.jpg 50w" sizes="(max-width: 648px) 100vw, 648px" /></p>
<h2>Blazor Wasm Standard Workflow</h2>
<p>If we now launch our application, access the Dev Tools window (F12), select the Application tab, and check the cache:</p>
<p><img loading="lazy" decoding="async" class="wp-image-3579 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-2-min.jpg" alt="" width="692" height="457" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-2-min.jpg 850w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-2-min-300x198.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-2-min-768x507.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-2-min-50x33.jpg 50w" sizes="(max-width: 692px) 100vw, 692px" /></p>
<p>Although we are still on the Home page and have not navigated anywhere else, we can see that our BlazorWasmLazyLoading.dll file has been downloaded and cached, which is typical. However, it also suggests that all of the components in this DLL have been downloaded. Of course, for small apps like this one, this is not a problem. However, it could significantly speed up downloads for a more complex application. So let&#8217;s work out a way to prevent it.</p>
<h2>Updating the primary project with new packages</h2>
<p>We&#8217;re going to use the Syncfusion Libraries in this article to work with the idea of lazy loading, so create a new Razor class library project called Weather and empty it out except for the <code>_Imports.razor</code> file. Additionally, this project needs to be referenced from the main one.</p>
<p>From the right-click menu of the project, choose Manage NuGet Packages.<br />
Afterward, use the word Syncfusion. Blazor, locate, and set up the proper Syncfusion.Blazor. Blazor NuGet packages. In this location, Syncfusion has been installed. The program makes use of the NuGet packages Syncfusion and Blazor Buttons.Blazor.Calendars. Look at the illustration below.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3580" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-3-min.jpg" alt="" width="850" height="222" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-3-min.jpg 850w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-3-min-300x78.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-3-min-768x201.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-3-min-50x13.jpg 50w" sizes="(max-width: 850px) 100vw, 850px" /></p>
<p>Configure the Syncfusion Blazor Service in Program.cs file as per the below code.</p>
<pre>using LazyLoading;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Syncfusion.Blazor;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add&lt;App&gt;("#app");
builder.RootComponents.Add&lt;HeadOutlet&gt;("head::after");

builder.Services.AddScoped(sp =&gt; new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSyncfusionBlazor();

await builder.Build().RunAsync();</pre>
<h2>Implementation Lazy Loading</h2>
<p>In order to use Blazor WebAssembly&#8217;s Lazy Loading feature, we must first make a change to the main project file. Therefore, from the context menu, right-click on the BlazorWasmLazyLoading project and choose EditProjectFile:</p>
<p><strong>LazyLoading.csproj</strong></p>
<pre class="">&lt;Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"&gt;

  &lt;PropertyGroup&gt;
    &lt;TargetFramework&gt;net6.0&lt;/TargetFramework&gt;
    &lt;Nullable&gt;enable&lt;/Nullable&gt;
    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
  &lt;/PropertyGroup&gt;

  &lt;ItemGroup&gt;
    &lt;PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" /&gt;
    &lt;PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Buttons" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Calendars" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Charts" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Data" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.DropDowns" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Grid" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Lists" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Navigations" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Notifications" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Popups" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.Spinner" Version="19.4.0.48" /&gt;
    &lt;PackageReference Include="Syncfusion.Blazor.SplitButtons" Version="19.4.0.48" /&gt;
  &lt;/ItemGroup&gt;
        &lt;ItemGroup&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Buttons.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Calendars.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Charts.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Data.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.DropDowns.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Grids.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Lists.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Navigations.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Notifications.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Popups.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.Spinner.dll" /&gt;
                 &lt;BlazorWebAssemblyLazyLoad Include="Syncfusion.Blazor.SplitButtons.dll" /&gt;
        &lt;/ItemGroup&gt;
        &lt;ItemGroup&gt;
          &lt;ProjectReference Include="..\Sample\Sample.csproj" /&gt;
        &lt;/ItemGroup&gt;
        &lt;ItemGroup&gt;
                &lt;BlazorWebAssemblyLazyLoad Include="Sample.dll" /&gt;
        &lt;/ItemGroup&gt;
&lt;/Project&gt;</pre>
<h2>Modifying App.razor File to Load the Required DLL</h2>
<p>We import the required utilizing directives before injecting the AssemblyLoader to load our assembly. The OnNavigateAsync event callback in the Router component is then given the OnNavigateAsync method. The OnNavigateAsync event callback is invoked just before switching to a new page. The AdditionalAssemblies property is also set to true. This attribute instructs our program to use additional assemblies to search for components that match the correct URIs.</p>
<p>In the @code section, we create the _lazyLoadedAssemblies private list of assemblies and the OnNavigateAsync method with the NavigationContext parameter. We check the currently required route inside the procedure using the context argument. If the fetch data route—the route of our FetchData component—matches, we use the LoadAssembliesAsync method to load the assemblies.</p>
<pre class="lang:default decode:true ">@using System.Reflection;
@using Microsoft.AspNetCore.Components.Routing;
@using Microsoft.AspNetCore.Components.WebAssembly.Services;
@inject LazyAssemblyLoader assemblyLoader;
&lt;Router AppAssembly="@typeof(App).Assembly" PreferExactMatches="@true" AdditionalAssemblies="@lazyLoadedAssemblies" OnNavigateAsync="@OnNavigateAsync"&gt;
    &lt;Found Context="routeData"&gt;
        &lt;RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /&gt;
        &lt;FocusOnNavigate RouteData="@routeData" Selector="h1" /&gt;
    &lt;/Found&gt;
    &lt;NotFound&gt;
        &lt;PageTitle&gt;Not found&lt;/PageTitle&gt;
        &lt;LayoutView Layout="@typeof(MainLayout)"&gt;
            &lt;p role="alert"&gt;Sorry, there's nothing at this address.&lt;/p&gt;
        &lt;/LayoutView&gt;
    &lt;/NotFound&gt;
&lt;/Router&gt;

@code {
    private List&lt;Assembly&gt; lazyLoadedAssemblies = new List&lt;Assembly&gt;();
    private async Task OnNavigateAsync(NavigationContext args)
    {
        try
        {
            if (args.Path.StartsWith("fetchdata"))
            {
                var assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Sample.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Buttons.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Charts.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Data.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.DropDowns.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Grid.dll" });
                lazyLoadedAssemblies.AddRange(assemblies);
            }
            if(args.Path.StartsWith("counter"))
            {
                var assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Calendars.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Buttons.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Lists.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Navigations.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Notifications.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Popups.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.Spinner.dll" });
                assemblies = await assemblyLoader.LoadAssembliesAsync(new[] { "Syncfusion.Blazor.SplitButtons.dll" });
                lazyLoadedAssemblies.AddRange(assemblies);
            }
        }
        catch (Exception ex)
        {

        }
    }
}</pre>
<p>Keep in mind that we won&#8217;t be able to locate the downloaded Sample.dll if we launch the app and search the cache. However, if we visit the FetchData page and the counter page, we can see the content of each page as well as the dependencies that have been downloaded.</p>
<p><img loading="lazy" decoding="async" class="wp-image-3581 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-4-min.jpg" alt="" width="773" height="388" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-4-min.jpg 850w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-4-min-300x151.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-4-min-768x386.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-4-min-50x25.jpg 50w" sizes="(max-width: 773px) 100vw, 773px" /></p>
<p><strong>Counter page</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3582" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-5-min.jpg" alt="" width="850" height="427" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-5-min.jpg 850w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-5-min-300x151.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-5-min-768x386.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/blazor-5-min-50x25.jpg 50w" sizes="(max-width: 850px) 100vw, 850px" /></p>
<h2>Conclusion</h2>
<p>Currently, we are aware of how to load various dependencies solely when necessary using Blazor WebAssembly&#8217;s lazy loading feature. As was already mentioned, this is a great feature because it speeds up the loading of our application.</p>
<p>All there is to it is that!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://topreviewhostingasp.net/implement-lazyloading-increase-blazor-website-performance/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
