Skip to content

Instantly share code, notes, and snippets.

@chfast
Created May 22, 2018 11:38
Show Gist options
  • Save chfast/7cb9ac0973af0f664b8d16e1e6b0dc04 to your computer and use it in GitHub Desktop.
Save chfast/7cb9ac0973af0f664b8d16e1e6b0dc04 to your computer and use it in GitHub Desktop.
WASM browser loader
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<h1>WASM loader</h1>
<pre id="log">Log:
</pre>
<script>
log = document.getElementById('log');
log.innerText += "started\n";
var startTime;
fetch('1.wasm')
.then(response => {
console.log(response);
log.innerText += "fetched\n";
return response.arrayBuffer();
})
.then(bytes => {
startTime = performance.now();
return WebAssembly.instantiate(bytes);
})
.then(wasm => {
log.innerText += "instantiated in " + (performance.now() - startTime) + " ms\n";
console.log(wasm);
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment