top of page
Writer's pictureThe Tech Platform

Creating SPA’s using C#

Just for the background SPA enables you to get a desktop app-like experience in a browser.


This is possible because of WASM (WebAssembly) which is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.


Seeing the future of the web and how the web ecosystem is evolving day by day Microsoft being the pioneer doesn’t want to hold back So they came up with an experiment called blazor which is a SPA framework that takes code in C# and compile it to wasm wich browsers understand and in May 2020 Microsoft officially released its first stable version for production use.


Blazor gets loaded, parsed, and executed way faster compared to JavaScript.Because its binaries are lighter than the textual JS files and, therefore, faster to decode.


We can also use JavaScript with C# using JSInterop which enables us to use numerous JS Apis as well.


here is the example snippet is written in C#



Blazor has two variants


1- Remote renderer



Benefits

  • Runs on the full .NET Core runtime

  • Fast development cycle

  • Small download size

  • Code is kept on the server and not downloaded to the client


Drawbacks

  • Doesn’t work well in high latency environments

  • No offline support — requires a constant connection to the server

  • Heavy resource demand on the server


2- Web assembly renderer



Benefits

  • Compiles to static files, meaning there is no need for a .NET runtime on the server

  • Work is offloaded from the server to the client

  • Apps can be run in an offline state

  • Codesharing, C# objects can be shared between client and server easily

  • The size of the payload is cut down to 100Kb from 2.4 MB when it was in preview

  • Ahead of time compilation (AOT)


Drawbacks

  • Restricted runtime. Apps have to operate in the browser’s sandbox and are subject to the same security restrictions as any JavaScript application.

So, .NET folks who don’t want to learn a new framework for modern web now can utilize C# to do the same there are many more things that will come up for blazor as it’s just the start.



Source: Medium


The Tech Platform

0 comments

Recent Posts

See All

Commentaires


bottom of page