https://github.com/tderflinger/tinygo-webapp-demo
Combine Go code in a JavaScript web application.
https://github.com/tderflinger/tinygo-webapp-demo
go javascript tinygo webassembly
Last synced: about 1 month ago
JSON representation
Combine Go code in a JavaScript web application.
- Host: GitHub
- URL: https://github.com/tderflinger/tinygo-webapp-demo
- Owner: tderflinger
- License: mit
- Created: 2021-12-29T22:13:39.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-29T22:24:14.000Z (over 4 years ago)
- Last Synced: 2025-06-02T04:07:44.977Z (12 months ago)
- Topics: go, javascript, tinygo, webassembly
- Language: JavaScript
- Homepage: https://www.tderflinger.com/en/go-lang-in-javascript-web-applications-webassembly
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tinygo-webapp-demo
Example web application that leverages TinyGo to combine
Go language code with a JavaScript web application.
## Building
Install Go modules:
```bash
$ go mod download
```
```bash
$ make demo
```
## Running
Start the local web server:
```bash
$ go run server.go
Serving ./html on http://localhost:8080
```
Use your web browser to visit http://localhost:8080.
In addition to the JavaScript, it is important the wasm file is served with the
[`Content-Type`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type)
header set to `application/wasm`. Without it, most browsers won't run it.
This simple server serves anything inside the `./html` directory on port
`8080`, setting any `*.wasm` files `Content-Type` header appropriately.
For development purposes (**only!**), it also sets the `Cache-Control` header
so your browser doesn't cache the files. This is useful while developing, to
ensure your browser displays the newest wasm when you recompile.
In a production environment you **probably wouldn't** want to set the
`Cache-Control` header like this. Caching is generally beneficial for end
users.
Further information on the `Cache-Control` header can be found here:
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
## License
MIT License