Closed joex92 closed 3 years ago
I'm new to WASM in general, so I'm using what I find in examples/demos...
Looks like it tried to download Box2D.wasm, but the server delivered a file with the wrong MIME type.
Check the "network" tab in your browser DevTools — is there a failed download for Box2D.wasm?
Or, did the download succeed, but the Response Header indicates an incorrect MIME type?
Server setup advice is detailed here:
https://emscripten.org/docs/compiling/WebAssembly.html#web-server-setup
For example, if you're using an Apache webserver, you can create a .htaccess
in the same directory with the following directive:
AddType application/wasm .wasm
ok thanks, I'll check the emscripten page, but why is it downloading it? isn't the *.wasm
already in there?
you've tag-loaded Box2D.js into the webpage, which is correct:
<script language="javascript" type="text/javascript" src="node_modules/box2d-wasm/build/Box2D.js"></script>
But this just gets you the first file, Box2D.js.
Box2D.js includes some bootstrapping code that attempts to fetch Box2D.wasm, which as you've demonstrated, is a separate file.
Box2D.wasm benefits from being a separate file, because this enables your server to serve it differently — it can be served with the MIME type application/wasm
, which tells your browser it's fine to apply streaming compilation to it.
ok, so do I have to tag-load Box2D.wasm into the webpage in the html file?
is .htaccess
the only way to set the MIME type? I've tried and for some reason my local server doesn't seem to load the .htaccess
file... I'm using a VScode web server extension to start a live web server...
.htaccess
is an Apache httpd concept.
I wouldn't be surprised if there were no way to do this with VSCode web server, but worth reading their documentation.
Tag-loading Box2D.wasm
into the webpage won't help. Box2D.js
intends to initiate the response itself. Moreover, tag-loading won't influence the MIME type.
I really recommend looking up how to serve the files using a more ubiquitous approach, like Apache httpd, nginx or Node.js express.
I still don't get how Node.js
server works so I'm going to try apache httpd...
anyways, isn't there a way to make the Box2D.js
file to read the *.wasm
file in the directory instead of fetching it from the server?
There's no way to make Box2D.js read Box2D.wasm from the filesystem, because of the browser's security model. Browser doesn't have access to your filesystem, only your network. Hence it has to use browser fetch()
API instead.
I'm using this code to initialize Box2D similar to what @Kripken did here in an example
So I'm getting this
I'm not running this local web server with npm, because I still don't get npm that much...