Skip to content

Commit bd7c907

Browse files
authored
Merge pull request #1723 from alexcrichton/instntiate-streaming
Improve instantiateStreaming fallback
2 parents 906ac15 + 20be0a3 commit bd7c907

File tree

1 file changed

+12
-6
lines changed
  • crates/cli-support/src/js

1 file changed

+12
-6
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,19 @@ impl<'a> Context<'a> {
536536
if (typeof WebAssembly.instantiateStreaming === 'function') {{
537537
result = WebAssembly.instantiateStreaming(response, imports)
538538
.catch(e => {{
539-
console.warn(\"`WebAssembly.instantiateStreaming` failed. Assuming this is \
540-
because your server does not serve wasm with \
541-
`application/wasm` MIME type. Falling back to \
542-
`WebAssembly.instantiate` which is slower. Original \
543-
error:\\n\", e);
544539
return response
545-
.then(r => r.arrayBuffer())
540+
.then(r => {{
541+
if (r.headers.get('Content-Type') != 'application/wasm') {{
542+
console.warn(\"`WebAssembly.instantiateStreaming` failed \
543+
because your server does not serve wasm with \
544+
`application/wasm` MIME type. Falling back to \
545+
`WebAssembly.instantiate` which is slower. Original \
546+
error:\\n\", e);
547+
return r.arrayBuffer();
548+
}} else {{
549+
throw e;
550+
}}
551+
}})
546552
.then(bytes => WebAssembly.instantiate(bytes, imports));
547553
}});
548554
}} else {{

0 commit comments

Comments
 (0)