What is Blazor?

Blazor is a UI framework, it allows developers to design and develop interactive rich UI components with C#, HTML, CSS, plus it is open sourced and free. So technically now you can create web pages directly in C# instead of JavaScript.

Blazor web application is nothing but a collection of web pages or to be precise razor pages, then each razor page will host bunch of blazor components and get this, this blazor web application could run on both server or on client. Isn't that cool?

In traditional architecture, server is designed with high level languages such as Java, C# and client is dominated by dynamic programming language such as javascript, now with blazor you can design both your server and client application in C#.

What is Blazor Server?

Have a look at the image below, you'd notice there is a server present somewhere on cloud or in office premises and it is communicating with a browser with something called SignalR. You can learn more about signalR here, but let me explain with a simple example.

What is Blazor Server

Image source: Microsoft docs


In Blazor server app, UI components (razor components) are stored on the server. Every UI updates, event calls are handled by SignalR which sends the updated data/component to the browser on demand. In order to run app smoothly browser need to have consistent connection with server. The browser has script, blazor.server.js which establishes the SignalR connection with the server.

Perks of using Blazor server app:

Disadvantages:

What is Blazor Assembly A.K.A. Blazor WASM?

WebAssembly is nothing but compact bytecode feeded to the browser.

Blazor webAssembly executes UI components directly from the client side with the help of .Net runtime. Blazor-WASM works same way as any other UI frameworks Angular or React but instead of JavaScript it uses C#. Blazor-WASM allows browsers to download the application so you run it directly from the browser. Meaning DLLs are loaded into the browser.

In 3 simple steps let's understand what is happening in the image below.

  1. You can develop code in C#, HTML, CSS which is encapsulated in razor files which get compiled by .NET assemblies.
  2. When you run the Blazor-WASM, .NET runtime and these compiled assemblies are downloaded into the browser.
  3. Now .NET runtime uses JavaScript interop to handle DOM manipulation to render the logical structure of razor components.

What is Blazor Assembly

Image source: Microsoft docs

Advantages

Disadvantages

I hope this clears the confusion once and for all.