Web Assembly: The Game Changer
What is web Assembly?
It is a low-level assembly language with a compact binary format that provides a way to run the code written in different high-level languages in the browser with the same speed as native.
Why C# for Client-side programming?
1.Robust and feature-rich language
- Code reusability is possible with C#
- With .Net Core maturing and being the main framework for the server-side programming it is a good idea to use the same stack for the development and using C# for the front-end development becomes an added advantage.
Running C# inside the Browser
To build this framework we need something which will run our beloved C# code in the browser. How we can do that? Thanks to our Game Changer Web Assembly, this will allow the C# code without using any plugins. Web Assembly is being supported into all mainstream browsers including the latest mobile browsers. Ok Cool �������� we have web assembly but how does it allow us to run the .net code into the Browser? The answer is MONO. Many of us have heard about MONO which is the official runtime for client platforms (Droid/IOS) which is used for running the .net into the browser.
Let’s see the bootstrap of the normal Blazor application. Whenever the application gets started it first loads the Blazor.js. Along with Mono.js (Present in the First Diagram) it bootstraps the mono runtime ( i.e. Mono.Wasm) which is Mono web assembly.
After this Mono.wasm loads the Application dll Which is Blazor.dll and the .net Runtime dll like mscorlib.dll and System.net are loaded.
Being .net developers we all know the Razor Engine combines C# with the HTML to generate the dynamic contents. We all know Razor runs on the server side but with the Blazor, Razor runs on the client side in which the Razor engine generates the C# code during compilation.
- C# part of Blazor creates the Render tree which is a tree of UI Items
- This event may be a button click which is processed by the C# part.
In this Overall process, we can see that no plugin is initiating the things, unlike Flash or Silverlight where some plugins needed to initiate the process.
Blazor Being inspired by today’s Popular SPA frameworks like Angular, React or Vue, it provides all the features which we will see below.
This was all about the Blazor and how it loads and runs under browser but to make Blazor a true Single-page application framework we will have features like component, routing, state management, unit testing and build optimization techniques.
All SPA frameworks are built up based on the components which can be a single pop up box or the user Registration form. In Blazor Components, there are classes which we can write in C# or normal cshtml we use in Razor, with this approach we can apply various patterns with the components.
When a new Blazor app is created then it adds some core features that every app needs such as Layouts, Rendering, Routing, DI, and Unit testing.
One of the most important aspects of any programming is the deployment of the application and for deployment, .net Core Middleware is provided which will help to deploy the Blazor UI Application. Code Sharing
We can make use of our existing Class Library with the Blazor allowing it to reuse the code which is well used and tested already.
This was all about Blazor and how it works. I hope it helps everyone.
Note Blazor has been in the experimental phase so far. It is not recommended to use Blazor for any production app for now until the final release is available from Microsoft.