Created
May 22, 2018 11:38
-
-
Save chfast/7cb9ac0973af0f664b8d16e1e6b0dc04 to your computer and use it in GitHub Desktop.
WASM browser loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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