Is Blazor Worth Your Time?

AWH
AWH
Jun 30, 2020 · 5 min read
Blazor is worth your time, graphic of a girl sitting at a desk
Blazor is worth your time, graphic of a girl sitting at a desk

Back in September, Microsoft released .NET Core 3 to much (deserved) fanfare. Included in it was a new web UI framework called Blazor. Then in May, Microsoft released Blazor 3.2, and with that released Blazor WebAssembly as a production-ready version of Blazor.

Blazor is a weird thing. First, because it’s two things. Second, because of what one of those things promises: a JavaScript-less future for the web.

Let’s step back and parse this out.

.NET Core and the Future of .NET

The main advantage that .NET Core has over the older .NET Framework is platform support. .NET Core is cross platform, and can run just about everywhere, whereas .NET Framework is tied to Windows. It’s also very stable, very fast, and comes with first-class tooling for developers.

WebAssembly

Importantly, WebAssembly is not a language that the vast majority of developers will ever write. Instead, WebAssembly is meant to be used as a compilation target. Instead of compiling code for a specific processor or operating system, you can compile code to WebAssembly and have your program run in a browser.

Blazor

The Two Sides of Blazor

Both models use the same component-oriented architecture, but are vastly different in how they run those components. The Server model runs, well, on a server. The code sent to the browser isn’t your code, but rather a small part of the framework which uses SignalR (a .NET library for managing real-time connections between a client and server) to send events from the browser to the server and DOM diffs back to the browser. The server renders your components and manages the interactions through SignalR.

Coding components
Coding components

The WebAssembly model is actually a bit easier to understand. All of the code, the framework and your components, run in the browser. Your C# code is compiled into DLLs like any other .NET application, but is then sent to the browser. Mono (a .NET runtime originally for Linux and the runtime behind Xamarin apps) is what is actually compiled to WebAssembly and it what runs your code in the browser. It’s very strange to open the browser dev tools and watch it downloading a bunch of DLLs.

Graphic of two coders discussing a project
Graphic of two coders discussing a project

Both models have their advantages. Server requires less work in the browser, but there is some latency in the UI since the network is involved. WebAssembly runs quicker, but requires a hefty initial download (about 2MB from the starter project).

Blazor — A Quick Sample

The sample components and layouts are a great way to get familiar with how you can build apps with Blazor.

> Side note: I don’t actually like the “standard” way of mixing C# and Razor together using the `@code` block. Instead, I prefer to make a separate C# file for the logic and leave the view code in the Razor file. This can be done easily as the generated classes from the components are partial classes and can be extended. More info here.

Blazor includes all you need to create full-featured, interactive web apps. Routing, form validation, and HTTP access are all available and are shown in the basic project template. And since it’s all in C#, .NET developers can get up and running quickly and can even reuse code from other parts of their systems. Blazor supports data annotation validation on forms, so business logic around model validation can be reused.

>Be aware that WebAssembly is still subject to the same browser sandbox that normal JavaScript-based web apps are forced to use.

Blazor WebAssembly — The Future I Want

One advantage of the WebAssembly model is that it’s independent of where or how it is hosted. When you publish a WebAssembly project, you get a folder full of files. A Blazor WebAssembly project is a static site and can be hosted anywhere. You don’t need to host it in Azure, or even run ASP.NET Core. And Blazor WebAssembly apps can be created as Progressive Web Apps to enable offline support since they don’t require a persistent network connection.

WebAssembly opens the door to a future where interaction on the web doesn’t rely exclusively on JavaScript, and Blazor proves that a framework can be created that takes full advantage of that. I’m excited to use Blazor for more projects, and I think it’s worth your time to check it out.

  • Andrew Moscardino, Software Developer at AWH

Citations

Manager, Daniel RothPrincipal Program, et al. “ASP.NET Core Updates in .NET Core 3.0 Preview 2.” ASP.NET Blog, 18 Nov. 2019, devblogs.microsoft.com/aspnet/aspnet-core-3-preview-2/.

The Startup

Medium's largest active publication, followed by +773K people. Follow to join our community.

AWH

Written by

AWH

An elite team of product creators and data problem solvers.

The Startup

Medium's largest active publication, followed by +773K people. Follow to join our community.

AWH

Written by

AWH

An elite team of product creators and data problem solvers.

The Startup

Medium's largest active publication, followed by +773K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store