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.
- The official Go WebAssembly docs to start diving a little deeper on the topic
- The WebAssembly Docs
- The growing WebAssembly section of awesome-go for neat libraries and tools in the ecosystem
- go-app.dev - the up and coming package for building PWA's (Progressive Web Apps) using Go and Wasm
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
.