Tutorials Blazor Architecture & Enterprise Patterns
Lazy Loading Assemblies to reduce bundle size
On this page
On-Demand Code
In a massive enterprise app, the user might only use 10% of the features. Lazy Loading ensures they only download the code they actually need.
1. Splitting the App
You can configure specific assemblies (DLLs) to be lazy-loaded. For example, if you have a massive 'Reporting' module with heavy dependencies like Syncfusion or DevExpress, you can defer downloading that DLL until the user actually navigates to the /reports page.
2. The Navigation Hook
In your App.razor, you listen to the OnNavigateAsync event. When a user requests a lazy-loaded route, you use the LazyAssemblyLoader service to fetch the DLL from the server. Once the download is complete, Blazor automatically registers the new types, and the navigation finishes seamlessly.
3. Architect Insight
Q: "Does lazy loading help with Blazor Server?"
Architect Answer: "NO. Blazor Server only sends UI diffs; the code is already on the server. This is a **WASM-only** optimization. For Blazor WASM, it is the single most effective way to keep your 'Initial Load' time under control as your application grows to hundreds of pages."