What’s inside the name Blazor?
WebAssembly, often abbreviated Wasm, is a new standard that can be run in modern web browsers bringing language diversity to the web platform. Wasm is a low-level assembly-like language featuring a compact binary format that makes it possible to run code written in multiple languages such as C/C++, Java, and Rust on the web with near-native performance.
What Blazor is not?
Blazor is not like Silverlight, Microsoft’s previous attempt at hosting in-browser applications. Silverlight required a browser plugin in order to run on the client, which prevented it from running on iOS devices.
Blazor does not require any kind of plugin installed on the client in order to execute inside a browser. Blazor either runs server-side, in which case it executes on a server and the browser acts like a dumb terminal, or it runs in the browser itself by utilizing WebAssembly.
Because WebAssembly is a web standard, it is supported on all major browsers, which means also client-side Blazor apps will run inside a browser on Windows/Linux/Mac/Android and iOS.
Blazor provides code encapsulation through its reusable web UI components. Blazor also allows both client and server C# code to share code and libraries.
ASP. NET Core provides this idea in the form of Razor components. Razor components are also the component model of Blazor. Therefore, Blazor components and Razor components are interchangeable.
Each Blazor component represents a different element in the application UI structure, such as a shopping cart, a news feed, or a comment section.
How Blazor Compares to ASP. NET Core MVC Applications
A regular ASP. NET Core MVC renders the UI as blocks of strings. Blazor, on the other hand, builds a render tree, which is not a string, but a representation of the DOM (Document Object Model) that is held in memory. Blazor keeps that representation. Any changes made to it (for instance, when a binding value is updated) will trigger a UI update for the affected DOM elements. This is a big difference from ASP. NET Core HTML Helpers and Razor Views, which render out strings.
Pros of Client-side Blazor
You can share validation code between client and server apps. Let’s say you have form validation logic to be applied on both the browser and the back-end. With Blazor, you can create a class library in .NET Standard 2.0, and share it across client and server apps. Any change in the validation logic automatically applies to both platforms.
Cons of Client-side Blazor
It’s also worth noting that, at present, there is limited debugging capability. Blazor still has to improve in this area. You can use a debugging tab in Chrome to debug and inspect the values of int, bool, and string types, and not much more than that. If you want to debug more effectively, you should put console logging throughout your client app.
Blazor vs. React
There are many developers, that would argue that React is the best library for web component development. Although it’s not an apple-to-apple comparison, we have to agree that React is well-established and earned its respect with a proven track record and by having a strong community around it.
On other hand, Blazor is new but it brings the flavor from its well-established counterpart Razor. So, it’s not entirely novel for developers. Moreover, .Net developers could have smoother transitions since Blazor uses C# for development.
Blazor vs. Angular
So, let’s assume, what makes Blazor so unique
- Build progressive web apps (PWAs);
- Create and use reusable components written in C#;
- Full debugging support on the server-side and debugging with some limitations on the client-side;
- Data binding with the HTML DOM (limited two-way binding);
- Share code between client and server in C#;
- Server and client-side models;
- Server-side rendering (aka pre-rendering) for higher performance;
- WebSocket connections;
- Works offline (client side WebAssembly only);
- Works in all modern web browsers including mobile browsers;
- Open source.
The development world is moving towards more straightforward and flexible ways to achieve results. Hence, the tools designed a decade ago will have to make space for a fresher and more innovative front-end approach. With Blazor, Microsoft offers a complete development ecosystem with a singular framework that can run anywhere.
Blazor solves real problems faced by web developers and it does so effectively and at almost no cost. Its learning curve is smooth and easy. It contains all the must-have features of a modern day SPA framework while keeping things simple. With Microsoft behind it and an excited community supporting it, Blazor is poised to make a big impact on future web development.