Web apps - Blazor - Hosting models
In this article
Blazor Server
Blazor Server is a server-side Java app development platform.
In a traditional server-rendered app, opening the same app in multiple browser screens (tabs or iframes
) typically doesn't translate into additional resource demands on the server. For the Blazor Server hosting model, each browser screen requires a separate circuit and separate instances of server-managed component state. Blazor considers closing a browser tab or navigating to an external URL a graceful termination. In the event of a graceful termination, the circuit and associated resources are immediately released. A client may also disconnect non-gracefully, for instance due to a network interruption. Blazor Server stores disconnected circuits for a configurable interval to allow the client to reconnect.
On the client, the Blazor script establishes the SignalR connection with the server. The script is served from an embedded resource in the ASP.NET Core shared framework.
The Blazor Server hosting model offers several benefits:
-
Download size is significantly smaller than when the Blazor WebAssembly hosting model is used, and the app loads much faster.
-
The app takes full advantage of server capabilities, including the use of .NET Core APIs.
-
.NET Core on the server is used to run the app, so existing .NET tooling, such as debugging, works as expected.
-
Thin clients are supported. For example, Blazor Server works with browsers that don't support WebAssembly and on resource-constrained devices.
-
The app's .NET/C# code base, including the app's component code, isn't served to clients.
The Blazor Server hosting model has the following limitations:
-
Higher latency usually exists. Every user interaction involves a network hop.
-
There's no offline support. If the client connection fails, interactivity fails.
-
Scaling apps with many users requires server resources to handle multiple client connections and client state.
-
An ASP.NET Core server is required to serve the app. Serverless deployment scenarios aren't possible, such as serving the app from a Content Delivery Network (CDN).
Blazor Server apps are hosted on Azure.
Blazor WebAssembly
The Blazor WebAssembly hosting model runs components client-side in the browser on a WebAssembly-based .NET runtime. The Blazor WebAssembly hosting model runs components client-side in the browser on a WebAssembly-based .NET runtime.
Blazor WebAssembly is a full-stack .NET web development tool that allows you to build web apps using a single codebase.
The Blazor script handles:
-
Downloading the .NET runtime, Razor components, and the component's dependencies.
-
Initialization of the runtime.
WebAssembly from Blazor reduces the download times of large apps by up to 50%.
-
Unused code is stripped out of the app when it's published by the Intermediate Language (IL) Trimmer.
-
HTTP responses are compressed.
-
The .NET runtime and assemblies are cached in the browser.
The Blazor WebAssembly hosting model offers several benefits:
-
For standalone Blazor WebAssembly apps, there's no .NET server-side dependency after the app is downloaded from the server, so the app remains functional if the server goes offline.
-
Client resources and capabilities are fully leveraged.
-
Work is offloaded from the server to the client.
-
For standalone Blazor WebAssembly apps, an ASP.NET Core web server isn't required to host the app. Serverless deployment scenarios are possible, such as serving the app from a Content Delivery Network (CDN).
The Blazor WebAssembly hosting model has the following limitations:
-
Razor components are restricted to the capabilities of the browser.
-
Capable client hardware and software (for example, WebAssembly support) is required.
-
Download size is larger, and components take longer to load.
-
Code sent to the client can't be protected from inspection and tampering by users.
Blazor Hybrid
-
Reuse existing components that can be shared across mobile, desktop, and web.
-
Leverage web development skills, experience, and resources.
-
Apps have full access to the native capabilities of the device.
-
Separate native client apps must be built, deployed, and maintained for each target platform.
-
Native client apps usually take longer to find, download, and install over accessing a web app in a browser.
-
.NET Multi-platform App UI (.NET MAUI)
-
Windows Presentation Foundation (WPF)
-
Windows Forms
Which Blazor hosting model should I choose?
Feature | Blazor Server | Blazor WebAssembly (WASM) | Blazor Hybrid |
---|---|---|---|
Complete .NET API compatibility | Supported | Not supported | Supported |
Direct access to server and network resources | Supported | Not supported† | Not supported† |
Small payload size with fast initial load time | Supported | Not supported | Not supported |
Near native execution speed | Supported | Supported‡ | Supported |
App code secure and private on the server | Supported | Not supported† | Not supported† |
Run apps offline once downloaded | Not supported | Supported | Supported |
Static site hosting | Not supported | Supported | Not supported |
Offloads processing to clients | Not supported | Supported | Supported |
Full access to native client capabilities | Not supported | Not supported | Supported |
Web-based deployment | Supported | Supported | Not supported |
After you choose the app's hosting model, you can generate a Blazor Server or Blazor WebAssembly app from a Blazor project template. For more information, see Tooling for ASP.NET Core Blazor.
Complete .NET API compatibility
Direct access to server and network resources
-
Third-party libraries, packages, and services might be costly to implement and maintain, weakly supported, or introduce security risks.
-
If one or more server-based APIs are developed internally by your organization, additional resources are required to build and maintain them.
Small payload size with fast initial load time
Near native execution speed
App code secure and private on the server
Run apps offline once downloaded
Static site hosting
Blazor WebAssembly apps can be hosted on the Blazor web server.
Offloads processing to clients
Full access to native client capabilities
Web-based deployment
Blazor web apps are updated on the next app refresh from the browser.