WebAssembly file - sending correct content type

I was creating a project where I used emscripten to build C/C++ code into asm.js or WebAssembly to run in browser (together with classic JavaScript code). After deploying to web server, although everything worked, I encountered some warnings about incorrect MIME type of the .wasm file.

In Chromium, the warning was:

wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
falling back to ArrayBuffer instantiation

In Firefox, it looked a little bit different:

wasm streaming compile failed: TypeError: Response has unsupported MIME type
falling back to ArrayBuffer instantiation

The solution is sending correct Content-Type header for the .wasm file:

Content-Type: application/wasm

When sending the file dynamically (e.g. from PHP), it can be easily done.

But my web application was only a bunch of static files and I did not want to bring any unnecessary complications to it by adding server-side code.

Creating .htaccess file in the directory where the .wasm file resides helped:

AddType application/wasm .wasm

Thankfully, my web hosting has not disabled this functionality or .htaccess completely.

Written on January 3, 2020