Web Development With Blazor: Introduction (Part 2)
Blazor Server
Blazor Server uses
SignalR to communicate between the client and the server, as shown in the
following diagram:
SignalR is an open-source
library for real-time communication that establishes a connection between
clients and servers. It can utilize various methods of data transport and
automatically identifies the most suitable protocol depending on the
capabilities of both the server and the client. SignalR prioritizes the use of
WebSockets, a transport protocol incorporated in HTML5. If for any reason
WebSockets is unavailable, it will smoothly revert to an alternative protocol.
Blazor is constructed
using reusable UI elements referred to as components. Every component comprises
C# code, markup, and may also incorporate additional components. Razor syntax
allows you to blend markup with C# code, or you can choose to write everything
in C# if preferred. User actions (like clicking a button) or events (such as a
timer) can cause the components to be refreshed.
The elements are
organized into a render tree, which is a binary representation of the DOM that
includes object states along with their properties or values. The render tree
monitors any alterations from the last render tree and transmits only the
modified elements over SignalR using a binary format to refresh the DOM.
On the client side,
JavaScript will capture the modifications and refresh the page as needed.
Compared to conventional ASP.NET, we solely render the specific component
rather than the whole page, and we transmit only the actual changes to the DOM
instead of the complete page.
Disadvantages Of Blazor
Server
- You must maintain a constant connection to the server because the rendering occurs on the server side. If your internet connection is poor, the site may fail to function properly. The main distinction from a non-Blazor Server site is that a non-Blazor Server site can send a page and then drop the connection until a new page is requested. In contrast, a Blazor site requires that connection (via SignalR) to remain active at all times (short disconnections are acceptable).
- There is no offline/PWA mode since it needs to be connected.
- Every interaction or refresh of the page necessitates a return trip to the server, potentially leading to increased latency. It's essential to note that Blazor Server transmits only the updated data.
- Given the need for a connection to the server, the demand on that server rises, making it challenging to scale. To address this issue, you can utilize the Azure SignalR hub, which will manage the continuous connections and allow your server to focus on providing content.
- To be able to run it, you have to host it on an ASP.NET Core-enabled server.
Advantages Of Blazor
Server
- It includes the necessary code to confirm that the connection is transferred to the client, allowing the site to maintain a minimal footprint.
- As we are operating on the server, the application can fully utilize the server's resources.
- The site will work on older web browsers that don't support WebAssembly.
- The code operates on the server and remains there, it cannot be decompiled.
- Given that the code runs on your own server (or in the cloud), you can directly access services and databases within your organization.
Conclusion
Details about Blazor server and its advantages as well as disadvantages are discussed.
Comments
Post a Comment