ASP.NET Blazor supports (before .Net 8) two main hosting models: Blazor WebAssembly and Blazor Server. These models determine how your Blazor application is executed and where the majority of the UI rendering takes place.
- Blazor WebAssembly: In this hosting model, the Blazor application is compiled into WebAssembly bytecode, which is then executed in the browser. This allows you to build rich, interactive web applications using C# and .NET languages without relying on JavaScript. The application code is downloaded to the client’s browser and executed locally, offering a highly responsive and interactive user experience.Key features of Blazor WebAssembly hosting:
- Client-Side Execution: The application code runs entirely on the client’s browser, reducing the need for server interaction during user interactions.
- Offline Capabilities: Blazor WebAssembly applications can work offline once they are loaded into the browser cache.
- Full .NET Interoperability: Blazor WebAssembly provides full access to .NET libraries, enabling code sharing between client and server components.
- Blazor Server: In the Blazor Server hosting model, the application’s UI logic is executed on the server, and the UI updates are sent to the client’s browser over a SignalR connection. This means that the client-side code is lightweight, primarily handling user input and rendering updates received from the server.Key features of Blazor Server hosting:
- Server-Side Execution: The UI logic is executed on the server, which can lead to improved performance and security.
- Automatic UI Updates: The application updates the UI by sending messages to the client browser over the SignalR connection.
- Reduced Client Resources: Blazor Server applications have a smaller initial download size compared to WebAssembly, as they don’t need to include the entire application code upfront.
Choosing between these hosting models depends on factors such as the project’s requirements, user experience goals, and architectural preferences. Blazor WebAssembly is often chosen for its rich client-side interactivity, while Blazor Server is suitable for applications that prioritize server-side processing and can benefit from reduced client-side resource requirements.
Both hosting models offer the benefits of the Blazor framework and allow developers to leverage their C# and .NET skills to build modern web applications.
Since .Net 8 preview versions, Microsoft introduces a medley of other substantial upgrades, most notably the introduction of Auto interactive render mode. This innovative mode seamlessly blends the Server and WebAssembly render modes, optimizing rendering performance by leveraging WebAssembly when the .NET runtime loads expeditiously, typically within the 100ms mark. Further enhancements include the extension of root-level cascading values, making them accessible across the component hierarchy.