Skip to content

Commit

Permalink
Merge pull request #1243 from fitzgen/instantiateStreaming-fallback-r…
Browse files Browse the repository at this point in the history
…ound-2

Apply the `instantiateStreaming` incorrect MIME type recovery for no-modules
  • Loading branch information
alexcrichton authored Feb 12, 2019
2 parents 6004454 + b858875 commit db4c3bf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,17 @@ impl<'a> Context<'a> {
}} else {{
const data = fetch(path_or_module);
if (typeof WebAssembly.instantiateStreaming === 'function') {{
instantiation = WebAssembly.instantiateStreaming(data, imports);
instantiation = WebAssembly.instantiateStreaming(data, imports)
.catch(e => {{
console.warn(\"`WebAssembly.instantiateStreaming` failed. Assuming this is \
because your server does not serve wasm with \
`application/wasm` MIME type. Falling back to \
`WebAssembly.instantiate` which is slower. Original \
error:\\n\", e);
return data
.then(r => r.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, imports));
}});
}} else {{
instantiation = data
.then(response => response.arrayBuffer())
Expand Down

0 comments on commit db4c3bf

Please sign in to comment.