Skip to content

Instantly share code, notes, and snippets.

@deezone
Created May 19, 2020 11:12
Show Gist options
  • Save deezone/e9d01ed993482bf89a460d02437e6d40 to your computer and use it in GitHub Desktop.
Save deezone/e9d01ed993482bf89a460d02437e6d40 to your computer and use it in GitHub Desktop.
WASM - Hello World - index.html
<!-- /out/index.html -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Go Wasm</title>
</head>
<body>
<script src="wasm_exec.js"></script>
<script>
if (WebAssembly) {
// WebAssembly.instantiateStreaming is not currently available in Safari
if (WebAssembly && !WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((res) => {
go.run(res.instance);
});
} else {
console.log("WebAssembly is not supported in your browser")
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment