Supporting compressed WASM files #3100
-
I have a very simple setup. I run wasm-bindgen --out-dir pkg --target web --reference-types --no-typescript --omit-default-module-path target/wasm32-unknown-unknown/release/index.wasm and I have an <!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<script type="module">
import init from './pkg/index.js';
window.addEventListener('load', async () => { await
init('./pkg/index_bg.wasm'); });
</script>
</body>
</html> It works great. How do I fetch and load a compressed file? I see that I can pass a promise, is this the strategy that I want (find an async js function to decompress and wrap it in that)? Like Forgive my ignorance. Javascript is quite a beast and I'm trying to have less of it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
That should work, although it doesn't have to be async. One of the many inputs supported by So, to load a compressed WASM file, you have to first decompress the wasm file into raw bytes, and then pass those bytes (or a promise resolving to them) to |
Beta Was this translation helpful? Give feedback.
-
Thanks @Liamolucko Any chance at all you or someone know of "the" solution for, say gzip? Inevitably I pick the wrong one (after wrestling with all this JS ....stuff). Just curious if you have good "obvious" solution. It's like going to the hardware store and the hammer aisle is half a block long ;-) Either way, much satisfaction! Thank you. Mark-as-answered... |
Beta Was this translation helpful? Give feedback.
That should work, although it doesn't have to be async.
One of the many inputs supported by
init
is bytes containing a wasm module, which will get compiled and instantiated. More specifically, anArrayBuffer
or aTypedArray
(general name forUint8Array
,Int32Array
, etc.)So, to load a compressed WASM file, you have to first decompress the wasm file into raw bytes, and then pass those bytes (or a promise resolving to them) to
init
.