I do not understand the difference between Blazor Web App(new template in .net 8) and Blazor Server App. Even the description provided in Visual Studio, for example, just sounds like different ways of saying the same thing to me. Why would you use Blazor Server App (BSA) over Blazor Web App (BWA) since BWA supports interactive & static server side rendering while also protecting your backend code on the server? Is BSA just an older, to be deprecated Blazor pattern?
I reviewed the documentation and created sample projects, but I still don’t understand why someone would choose Blazor Server App over Blazor Web App.
2
Answers
When you continue with the Server App you will see it can only be created with dotnet 7 and below, the Web App only with dotnet 8.
They are templates from 2 different generations. The new Web App can deliver everything the older ServerApp does and it adds a few more options.
See New Blazor Web App template
Blazor server, all the HTML is rendered in the server side so that we need a websocket connection to make the UI interactive. While blazer web assembly enable UI interactive in the client side because it downloaded the .net runtime to the client.
So they have advantages and disadvantages. I think both the advantages and disadvantages are brought from the render mode.
Using blazor server means it would route to the right component then render the HTML in the server side and make it as the response to the client. Blazor server is a persistent stateful connection model which means rendering in the server then set up a websocket connection so that it could be interactive to the operations in the web page. In the first-time loading, it would be faster then Wsam as Wasm needs to load the .net runtime. It’s much friendly for the clients which are not so "powerful"(rendered in the server). And it also means it would cost server side performance, so we need to pay for the server resources, and it will be affected when we have network latency, or the websocket connection is disconnected.
Using blazor web assembly means we need to care the load-time performance as it downloads the runtime. But it would bring much benefits for UI latency, all the interactivities are handled in the client rather then in the server, and we can it is a normal SPA like React/Vue, so we can send http request to call web API, we can create websocket connections to build a real-time chat. The client browser does more than using blazor server so it also has a higher requirement for the browser.
Then blazor web app is a full-stack template which becomes more powerful by different render modes.
When using blazor web app, which is similar to blazor server, but there’s no web assembly, no web socket involved here, because blazor web app allows us to have client-side interactivity on a per page or per component, we can also enable it for the whole application. I mean we can have server side rendering and client side rendering both in the same project. It means we can push much task to the client so that it won’t cost the server resources and it is also good when we don’t want to load the runtime in the first time and so on. Any way, I want to say it’s solved much disadvantages for both server and Wsam.
Much details can be seen here: https://www.youtube.com/watch?v=QD2-DwuOfKM