So, you’ve been looking into creating a new web app with Blazor but have run into one dilemma: do you go with Blazor WebAssembly (WASM) or Blazor Server for your application and components?
Blazor Server fully runs the application on the backend. The C# and Razor code is run on the backend and generates client side HTML and Javascript on the frontend. User interaction on the frontend is sent to and from the server. The server processes the action, updates the app’s UI, and sends the changes back to the user’s browser. Blazor Server uses a SignalR connection (a WebSocket connection) to maintain real-time communication between the server and the frontend client.
This means that the browser doesn’t execute any application logic and most of the work is done on the server. This is beneficial for a few reasons:
Now, there are some downsides to using Blazor Server, including:
Blazor WebAssembly (WASM) is Blazor’s other hosting model. The entire app is downloaded to the user’s browser and is run locally. WASM executes C# code in the browsers runtime. It doesn’t require constant communication with the server unless doing things like fetching data.
Some of the pros of using WASM:
While that may sound dreamy, there are some downsides to using WASM as well:
Rendering modes in Blazor define how components are rendered and made interactive, complementing the hosting models (Blazor Server or WebAssembly). They can prerender static HTML for SEO, enable interactivity on the server (Blazor Server), or run fully client-side (Blazor WebAssembly). Modes like Interactive Auto combine server-side rendering for fast initial load with client-side interactivity for the best of both worlds, tailoring the app's behavior to the hosting model's strengths and weaknesses.
Here’s an overview of rendering modes in Blazor:
Render Mode |
Description |
Render Location |
Interactive |
Static Server |
Performs static server-side rendering (SSR), generating non-interactive HTML. |
Server |
No |
Interactive Server |
Executes interactive SSR using Blazor Server, enabling dynamic interactions via a SignalR connection. |
Server |
Yes |
Interactive WebAssembly |
Conducts client-side rendering (CSR) using Blazor WebAssembly, running the app entirely in the browser. |
Client |
Yes |
Interactive Auto |
Initially uses interactive SSR with Blazor Server, then switches to CSR on subsequent visits after downloading the Blazor bundle. |
Server, then Client |
Yes |
To apply a render mode to a component, use the @rendermode directive in the component's Razor file. For example:
<YourComponent @rendermode="InteractiveServer" />
This directive specifies that YourComponent should use the Interactive Server render mode.
Blazor Server benefits most from rendering modes that optimize SEO or reduce latency for interactivity.
Blazor WebAssembly benefits from rendering modes that provide prerendering for SEO while retaining its client-side strengths.
Now that you know the pros can cons of both Blazor Server and WebAssembly, which one do you choose for your project?
The Answer: It depends. Yeah, I know this is a cliche answer but it’s true and it is mostly dependent on the nature of your application and your business needs.
You Should Use Blazor Server if you have:
You Should Use Blazor WASM if you have:
If you’re still unsure which hosting model to use for your application, we can help you out! Our WebMAP for Blazor conversion tool can automate your code migration from WinForms/Desktop C# to Blazor - via both Blazor Server AND Blazor WASM.
Feel free to contact us with any questions regarding Blazor or migrating to Blazor.