Some notes on Blazor

What is Blazor?

It’s a new .Net technology that allows to implement web’s client side codes using C# and compiling to Web Assembly, a new web standard that all modern browsers implement (it’s meant to be faster as it’s compiled).

It also makes use of the old Razor technology used at MVC views, that’s why they’ve got similar names (Browser+Razor = Blazor).

It allows you to create SPAs (Single Page Applications) using .Net technologies only, no javascript.

Some notes

Blazor is similar to Angular in which it allows you to create your own pieces of code, add them as HTML tags and include two-way data binding between the codes and the view. It seems very similar to Angular1 in how it achieves it and it doesn’t seem very flexible on how to name a “Component/Directive”, but I haven’t checked it that much.

Due to it compiling to WebAssembly, it seems to be very clever on keeping track of each file added on its own, not having to create a manual index of every single piece to be added like Angular modules. And yet, in case you want different modules with different features, I’m not sure how it would handle it, but we don’t really use modules so it’s not an issue for us.

To do that, “views” are just .cshtml files added to the “Views” folder, while “components” are .cshtml files added to the Shared folder, just like Razor would organise its pieces of code, and that automatically handles all the app structure, no need to require or import anything.

Unless I got it wrong, it seems to allow to generate pages on server side like MVC-Razor, which while not always useful can sometimes be, essentially preparing some stuff before sending it to the client. I am so used to request the HTML on one side and the data on the other through AJAX nowadays that this now sounds unefficient (most of the time you send more data and require more bandwidth), but it could reduce the client’s machine stress pre-processing some stuff. Angular can also do this but requires to set some flags down to write HTML from the codes.

Setbacks

While it looks pretty nice and has some useful stuff, it can’t make use of all JS libraries available as it isn’t using javascript at all and I don’t think you can combine them easily like you would with Razor or any other technology adding JS on top of that. I don’t think it’s impossible but as you are double binding stuff and everything adding some scripts o top of that can be tricky, so it wouldn’t be very efficient to do that.

Considering the huge amount of already-made wheels in the JS world, I have my doubts that a technology that can’t cooperate with it to ease transitioning will succeed.

Update: Looks like, they are working on this issue in particular and there is a way to combine them, but need to check how viable it actually is.

Leave a Reply

Your email address will not be published. Required fields are marked *