Tuesday, September 26, 2023

Blazor Hosting models

Blazor has 2 hosting models which are:
• Blazor Server
• Blazor WebAssembly

Blazor WebAssembly

This approach is also called as the client-side hosting model, which involves running the application directly within the browser via WebAssembly. As a result, the browser downloads everything required for the application, including the compiled application code, its dependencies, and the .NET runtime.


• Once the app is downloaded to the browser it becomes fully functionable and so there is no server-side dependency.
• No requirement of an ASP.NET Core web server to host the app.


• Initial Download size is quite large, a few MB. So, app is slow to load.
• Browser should support WebAssembly. Older browsers do not do this.

Blazor Server

This is also called the server hosting model and, in this model, the application is executed on the server from within an ASP.NET Core application. Between the client and the server, a SignalR connection is established.

When a client-side event, such as a button click, occurs, the event information is sent to the server via the SignalR connection. The server processes the event and calculates a diff (difference) for the generated HTML, which is then sent back to the client. Finally, the browser updates the UI based on the changes received.

The important point is the entire HTML is not sent back again to the client, it’s only the diff that is sent to the client.


• Download size is smaller than a Blazor WebAssembly app. So, the app loads much faster.
• The app takes full advantage of .NET runtime and APIs.
• Blazor Server apps work with browsers that don’t support WebAssembly.
• Blazor is based on Razor Pages so you can use features of C#, Razor Pages and ASP.NET Core which makes is very easy to learn this framework in a very short time.


• A persistent HTTP Connection is required all the time. When this connection is lost then Blazor stops working.
• Every user interaction involves a network hop.

In the next section, we will discuss about how to install a blazer on our machine and how to use it.