Originally posted on: samueleresca.net
Usually, there are two ways of translating to machine language:
- Interpreter: interpreters are quick to get up and running. You do not have to go through that whole compilation step before you can start running your code. You just start translating that first line and running it;
- Compiler:Â it takes a more time to start up because it has to go through that compilation step at the beginning. But then code in loops runs faster, because it does not need to repeat the translation for each pass through that loop;
Compilers take high-level programming languages and translate them to machine code. WebAssembly is a machine language for a conceptual machine, the browser.Â The compiler tool chain that currently has the most support for WebAssembly is called LLVM. There is also another tool called Emscripten. It is a bit easier to use at the moment. It has its own back-end that can produce WebAssembly by compiling to another target, called asm.js, and then converting that to WebAssembly.
Web Assembly in ASP.NET Core is a lie.Â The current status of web Assembly in ASP.NET Core can be found here: https://github.com/aspnet/Mvc/issues/6457.
However, Â Steve Sanderson put together a cool prototype of Razor running in the browser on WebAssembly:Â Blazor. Blazor isÂ an experimental web UI framework using C#/Razor and HTML, running client-side via WebAssembly. It runs .NET code in the browser via a small, portable .NET runtime called DotNetAnywhere compiled to WebAssembly.
DNA stands for Dot Net Anywhere.Â It is written in C and has been designed to be as small and portable as possible, allowing .NET software to be used on resource-constrained devices where it is not possible to run a full .NET runtime. DNA can be compiled as .wasm and executed in a browser.
Blazor runs over theÂ .NET Core 2.0 preview 3Â or later. There are two way to setup a project sample:
- Visual Studio 2017.3Â or later: by installing the following extension.Â Then useÂ File->New projectand chooseÂ Blazor ApplicationÂ from theÂ WebÂ category;
- Visual studio Code, Rider IDE: the project scaffolding extension is only available on Visual studio. But you can find the base template of project on GitHub: Â https://github.com/SteveSanderson/Blazor/tree/master/template/MyApplication;
To start the application in VS, just press F5 or Ctrl+F5 as usual.Â To start the application on the command line, runÂ
dotnet blazor serve. Once your app is running, you can edit itsÂ
cshtmlÂ files, and the application will update automatically.
In conclusion, Blazor is just an amazing experiment. It is NOT a production-ready solution. But the idea behind the project and the possibility to use Web assembly in ASP.NET Core can be an amazing feature. More in general, the same concept can be applied to other languages, for example: Java, Swift or Go.
Well, as you can see from the screenshot the transferred size is
566K Jan 4 22:03 angular2.min.js. So, Blazor framework is a pretty good strarting point. For more information:
Cover image by:Â Katsushika Hokusai - Storm below the Mountain. Cheers :)