About WebAssembly module files
The fast loading path, WebAssembly.instantiateStreaming(fetch(url)), compiles while downloading, but only if the response has exactly application/wasm. With any other type it throws “Incorrect response MIME type”, and many loaders silently fall back to the slower path of downloading the whole file first.
- WebAssembly binaries often shrink by half or more with gzip or Brotli, so make sure compression is enabled for this type.
File signature
WASM files start with 00 61 73 6D ("\0asm"). The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .wasm with the right Content-Type
Content-Type: application/wasm
application/wasm wasm;
AddType application/wasm .wasm
@wasm path *.wasm
header @wasm Content-Type "application/wasm"
curl -sI https://example.com/file.wasm | grep -i '^content-type'
# Content-Type: application/wasm
Set the type in code
res.set('Content-Type', 'application/wasm');
import mimetypes
mimetypes.add_type('application/wasm', '.wasm') # if your system doesn't know it
mimetypes.guess_type('file.wasm')[0] # 'application/wasm'
mime.AddExtensionType(".wasm", "application/wasm")
w.Header().Set("Content-Type", "application/wasm")
Accept .wasm uploads
<input type="file" accept=".wasm,application/wasm">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
-
.js (
text/javascript): JavaScript -
.mjs (
text/javascript): JavaScript module -
.bin (
application/octet-stream): Binary data
More web
.html , .css , .svg , .webmanifest , .rss , .vtt . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .wasm files?
application/wasm. The full header is "Content-Type: application/wasm".
Why does my server send the wrong Content-Type for .wasm?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .wasm is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is WASM?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. WASM files start with 00 61 73 6D ("\0asm"). The MIME type lookup on this site reads them for you when you drop a file on it.