Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 41 ยท Hosting Models and Deployment

Blazor Hosting Models and Render Modes

Compare Blazor Server, WebAssembly, Auto and static server rendering, learn how render modes are chosen per component, and decide which model fits your app.

"Where does my component's C# actually run?" is the most important architectural question in Blazor. The framework can run your components on the server and stream UI updates to the browser, in the browser on a .NET runtime compiled to WebAssembly, or a mixture of both. These choices are called hosting models (older name) or render modes (current name, since .NET 8). Your Razor code stays almost the same; what changes is latency, scalability, startup time and what the code is allowed to touch.

This lesson is conceptual. None of these hosts can run inside this tutorial's runner, so the configuration snippets are real and read-only, and the runnable parts are stand-ins in plain C# that model the cost trade-offs.

The four render modes

Render mode Where components run Interactive? Typical use
Static server (SSR) Server, once per request; HTML is sent No (links and forms only) Content pages, marketing, SEO
Interactive Server Server, over a live SignalR connection Yes Internal tools, fast start, secure data access
Interactive WebAssembly Browser, on the .NET WASM runtime Yes Offline-capable, no server per user
Interactive Auto Server first, then WebAssembly once downloaded Yes Fast first load, then client speed

A Blazor Web App (the modern project template) can use all of them in one app, choosing per page or even per component. Older projects were one of the two original templates: Blazor Server (what is now Interactive Server) or Blazor WebAssembly standalone.

flowchart TB
    R["Request"] --> S{"Render mode"}
    S -->|"Static SSR"| A["Server renders HTML<br/>no live connection"]
    S -->|"Interactive Server"| B["Server renders and keeps a circuit<br/>UI diffs over SignalR"]
    S -->|"Interactive WebAssembly"| C["Browser downloads .NET runtime<br/>runs components locally"]
    S -->|"Interactive Auto"| D["Starts on Server,<br/>later switches to WebAssembly"]

Same components, four places they can run.

Interactive Server

With Interactive Server the browser opens a WebSocket (SignalR) connection called a circuit. Component code runs on the server. When you click a button, the browser sends a tiny event message; the server runs your handler, computes a render tree diff and sends back only the DOM changes.

Strengths:

  • Tiny download and fast start: no runtime to fetch.
  • Full access to server resources (databases, secrets) directly from component code, so no API layer is required.
  • Your C# never leaves the server.

Costs:

  • Every interaction needs a network round-trip, so high latency feels sluggish.
  • Each active user holds a circuit and memory on the server, so capacity planning matters.
  • If the connection drops, the circuit is lost (Blazor shows a reconnection UI), and the app does not work offline.

Interactive WebAssembly

The browser downloads the .NET runtime and your assemblies (once, then cached) and runs components locally. After the download no server is needed for UI interactions.

Strengths: instant UI response, works offline (with a service worker), scales to a static file host because the server does not run UI code.

Costs: a larger first download, slower startup, and all your component code is visible to the user (never put secrets in it). Data access goes through HttpClient to an API you provide (see Calling APIs from Blazor with HttpClient).

Interactive Auto

Auto starts on the server for a fast first interaction, downloads the WebAssembly bundle in the background, and uses WebAssembly from then on. You get a quick first load and client-side speed, at the price of the most complexity: your component must work in both places, so it cannot assume direct database access (it may run in the browser) and it needs an abstraction, usually an interface with a server implementation and a client implementation that calls an API.

Choosing a mode in code

In a Blazor Web App you opt in with @rendermode. Without it a component renders as static server output.

RAZOR
@page "/counter"
@rendermode InteractiveServer

<h1>Counter</h1>
<button @onclick="() => count++">Clicked @count times</button>

@code {
    private int count;
}
RAZOR
@* Apply to a single component instance *@
<Chart Data="sales" @rendermode="InteractiveWebAssembly" />
RAZOR
@* Apply to the whole app *@
<Routes @rendermode="InteractiveAuto" />

And Program.cs enables what you use:

C#
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents()
    .AddInteractiveWebAssemblyComponents();

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(Client._Imports).Assembly);

Components that must run in the browser live in the .Client project, because only that project is shipped as WebAssembly.

A render mode set on a component applies to its children, but a child cannot change the mode chosen by its parent. Also, parameters passed from a server-rendered parent to an interactive child must be serializable, so you cannot pass a render fragment or a delegate across that boundary.

Static server rendering is not "less Blazor"

Static SSR renders HTML on the server and sends it, much like Razor Pages or MVC views, with enhanced navigation that updates the page without a full reload and enhanced form handling. It needs no connection and no runtime download, so it is the cheapest mode and the best for SEO. Interactive modes are for the parts of the page that need rich behavior. Start static and add interactivity where it pays off.

Comparing costs with a model

Numbers vary with your app, but the shape of the trade-off is predictable. This stand-in estimates, for each mode, the first-load payload, the latency of a click and the server memory used by concurrent users. The constants are illustrative assumptions, not benchmarks, so change them and see how the ranking moves.

C# Stand-in: a cost model for render modes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Read the table, not the digits: Server wins first load and loses on click latency and RAM; WebAssembly is the opposite; Static SSR is cheapest but cannot react to clicks; Auto buys both at the cost of more code.

A decision helper

A rule of thumb you can run: answer a few yes/no questions and get a suggestion.

C# Stand-in: which render mode fits?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Treat this as a starting point. Real decisions also weigh team skills, hosting budget and how latency-sensitive the UI is.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In Interactive Server mode, where does your component code run?

    The browser holds a circuit; events go to the server and render diffs come back.
  2. 2. Which mode needs no server-side UI work per user after the first download?

    After the runtime is cached, components run in the browser and only API calls reach the server.
  3. 3. What is a main cost of Interactive Auto?

    Because a component may run in either place, it must not assume direct server-only resources.
  4. 4. How do you choose a render mode for one component in a Blazor Web App?

    Use @rendermode InteractiveServer, InteractiveWebAssembly or InteractiveAuto on the component or its usage.

Summary

  • Blazor components can run on the server, in the browser via WebAssembly, or both (Auto); static SSR sends plain HTML.
  • Interactive Server has a fast start and secure access but needs a connection and server memory per user.
  • WebAssembly gives fast UI and offline potential at the cost of a larger first download and public code.
  • @rendermode chooses the mode per app, page or component; client components live in the .Client project.
  • Start with static rendering and add interactivity where it is needed.

Next: Prerendering and Streaming Rendering