Course contentsShow
← C#
Lesson 1322 of 1,90812. Modern Frontend with Razor and BlazorFree lesson

Blazor Server vs WebAssembly

Contrast the lifecycle and transport protocols of Blazor Server and Blazor WebAssembly.

In this lesson, you will learn how Blazor Server and Blazor WebAssembly differ in their execution lifecycle and the network protocols they use to keep your UI in sync.

Blazor Server: The SignalR Orchestrator

Blazor Server executes your C# code directly on the web server. When a user interacts with the UI—such as clicking a button—the event is sent over a SignalR connection (a persistent WebSocket). The server processes the logic, calculates the UI changes, and sends back the smallest possible set of DOM updates, which the client-side JavaScript then applies.

  • Lifecycle: The state resides entirely in the server's memory for each user session.
  • Transport: Relies heavily on a constant, low-latency connection. If the network drops, the UI becomes unresponsive until the connection is restored.

Blazor WebAssembly (WASM): The Client-Side Engine

Blazor WebAssembly downloads your compiled .NET DLLs and the Mono/WASM runtime directly to the browser. Your C# code executes on the user's CPU, just like JavaScript would.

  • Lifecycle: The application is self-contained. Once the initial payload is downloaded, the server is only needed to fetch data (typically via standard HttpClient calls to APIs).
  • Transport: Uses standard HTTP/REST patterns. Because the logic runs locally, the app remains interactive even without a constant active connection to the backend.

Comparison Table

FeatureBlazor ServerBlazor WebAssembly
ExecutionServer-sideClient-side (Browser)
TransportSignalR (WebSockets)HTTP / API Requests
LatencyDependent on network speedDependent on client hardware
StartupInstant (very thin client)Slower (requires runtime download)

For example, a high-frequency UI update (like a real-time ticker) is often smoother in Blazor Server because the "heavy lifting" happens on a powerful server. Conversely, a data-entry form works flawlessly offline in WebAssembly, making it more resilient for users with unstable internet.

Key Takeaway: Blazor Server uses a real-time SignalR circuit to mirror server-side logic in the browser, while Blazor WebAssembly shifts the execution environment to the client, utilizing the browser’s runtime to handle logic locally.