Introduction to Blazor Server Projects

Blazor Server uses SignalR to communicate between client (browser) and server. SignalR is an open-source library for transporting data between client and server. SignalR automatically selects the best transport protocol based on client and service capabilities. It uses WebSockets transport protocol, which is built on HTML5. If WebSockets is not enabled, it will use the best available protocol.

 

In Blazor projects, we develop components for common code that include UI markup and C#. Razor syntax can mix C# and markup (HTML) codes. Blazor components can have another one or more Blazor components. User actions like clicking a button can update these components. When we run the application, Blazor components render into a render tree, a binary representation of DOM that contains objects, states, properties, and any values if we have them. This render tree will track any changes compared to the previous render tree. If we run the application for the first time, it will keep everything as we don’t have any prior render tree. These changes will send over SignalR using a binary format to update the DOM. SignalR is nothing but a javascript file; JavaScript receives the changes from server and updates the browser accordingly. Blazor Server application sends only changes to the DOM (browser), not the entire page.

 

Advantages:

  1. In the Blazor Server project, everything runs on the server, and only changes are sent to the Client over SignalR. Blazor Server project can utilise all server capabilities as it runs on the server.
  2. Blazor server projects render everything on the server and send only changed HTML to the browser, and it works on any browser, even old browsers, unlike WebAssembly projects.
  3. Code executes on the server; that means we will not have the code at the client, and there is no way to decompile the code. Blazor Server projects are very much secured.

 

Disadvantages:

  1. For Blazor Server projects, the client and server should always be connected. If the client has a bad internet connection, the Blazor server application will not work as expected.
  2. Each and every user action will do a round trip to the server, which might result in higher latency even though the Blazor Server project sends only changes to the browser.
  3. All code executes on the server, and the server load increases, affecting the performance.
  4. To host the Blazor Server project, we need Asp.Net Core installed on the server.