/go-in-the-browser

A simple example of running Go in the browser using Wasm.

Primary LanguageJavaScript

Go in the Browser, using Wasm

Have you ever wanted to solve some specific problems in your web application, but JavaScript kept getting in the way?
Did you ever think to yourself "Why oh why can't I just use Go for this surely very valid use-case?"
Or maybe you just heard the hubbub around WebAssembly (Wasm) and wanted to see what the big fuss was all about?

Well if you even remotely responded with an "eh, I guess" to any of the above: look no further. This repository serves as a minimal, barebones example of what it takes to get a Go program compiled down to a Wasm module, running in your browser and interacting with JavaScript.

👉 Try it out live.

Further Reading

Running locally

Go version >1.22 is the only local requirement.

Start up a development server and build your Wasm module using:

make run

Any change you make to the Wasm module requires a rebuild of the build-wasm target. For a simple use-case such as this you may opt to periodically run a build:

watch make build-wasm

Builds from the first onward should only actually occur when changing the contents of ./cmds/wasm.