Created
September 5, 2019 21:39
-
-
Save gonzaloruizdevilla/e85a6395b1432ef2385d9aaf532c4fb4 to your computer and use it in GitHub Desktop.
This file contains 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
async function maybeInstantiateStreaming(path, ...opts) { | |
// Start the download asap. | |
const f = fetch(path); | |
try { | |
// This will throw either if `instantiateStreaming` is | |
// undefined or the `Content-Type` header is wrong. | |
return WebAssembly.instantiateStreaming( | |
f, | |
...opts | |
); | |
} catch(_e) { | |
// If it fails for any reason, fall back to downloading | |
// the entire module as an ArrayBuffer. | |
return WebAssembly.instantiate( | |
await f.then(f => f.arrayBuffer()), | |
...opts | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment