By compiling with the following options,
emcc -s WASM=1 main.cpp -o index.js
emscripten generates an index.wasm, and a js wrapper index.js.
The js wrapper loads the .wasm file located in the same directory, using XMLHttpRequest when it's running in a browser.
So what should I do if I need to load of the .wasm file manually? The loading part seems hard-coded in the wrapper.
Here are some circumstances where I need this:
- I need to serve the
.wasmfile from another url (for example from CDN). - The url to download the
.wasmfile is dynamically generated. - The code is running in a sandbox where
XMLHttpRequestis not allowed, there is only an API likegetMyData('some_file'). - I need to embed all the files as base64 string.
I know I could generate the .wasm file only, by
emcc -s WASM=1 main.cpp -o index.wasm
But then I loses the wrapper, which is not trivial when using some emscripten APIs like SDL and GLES.