WebAssembly: Introduction to WebAssembly using Go

Click for: original source

Welcome to tutorial no. 1 of our WebAssembly tutorial series. JavaScript has been the only programming language that the browser understands. JavaScript has stood the test of time and it has been able to deliver the performance needed by most web applications. But when it comes to 3D games, VR, AR, and image editing apps, JavaScript is not quite up to the mark since it is interpreted. Published on golangbot.bot by Naveen Ramanathan.

WebAssembly is a virtual assembly language for the browser. When we say virtual, it means that it cannot be run natively on the underlying hardware. Since the browser can be running on any architecture, it is not possible for the browser to run WebAssembly directly on the underlying hardware.

The existing JavaScript engines have support to run WebAssembly’s Virtual Assembly Code. WebAssembly is not meant to replace JavaScript. It is meant to operate hand in hand with JavaScript to take care of performance critical components of a web application. It is possible to make calls from JavaScript to WebAssembly and vice versa.

In this tutorial, we will cross compile a Go application to WebAssembly and run it on the browser. The article then describes following:

  • What is WebAssembly?
  • What are we developing?
  • Hello World WebAssembly program cross compiled from Go
  • Javascript glue
  • WebServer
  • Coding the JSON formatter
  • Exposing a function from Go to Javascript

… and more. Plenty of code examples together with excellent explanation what is happening in the code. The source code for this tutorial is available here and there is part 2 odf this article available, too. Very insightful!

[Read More]

Tags apis web-development distributed browsers javascript