Design: WebAssembly MIME Type

Created on 9 Feb 2017  路  12Comments  路  Source: WebAssembly/design

Files served over HTTP should have an associated MIME type so the consumer has some idea of what to do with it in the absence of any contextual hints. For example, if there's a desire to someday allow WASM to be loaded via the HTML <script> element, a MIME type would be a strong hint to the browser that it shouldn't try to parse it as JavaScript. This also allows web server extensions that act based on MIME type (like compression modules) to make a better choice (WASM compresses well so automatic server caching of a compressed response is beneficial).

application/webassembly is my personal preference, as it's similar to application/javascript in that the technology name is fully spelled out.

Most helpful comment

@annevk , @jfbastien At the time I wrote this issue, the MIME hadn't yet been publicly decided as application/wasm. I wasn't aware that there was already considerable momentum behind that choice (relatively little of the team's activity is published). I don't have a problem with the decision 馃檪

All 12 comments

If a custom decoder and translator is used then the source might be more like a binary blob with no well defined encoding. Perhaps it still helps to have a MIME type for it, so it is known to be an input into this pipeline, but it might want something distinct from application/webassembly which might be reserved for the raw input into the compilation stage?

@wllang You can use custom decoders and translators with any file format, not just WASM. The most famous of example of this is GZIP, which is communicated with the Content-Encoding header, and it's only used if the request includes a matching Accept-Encoding. You're not blocked from anything like you describe by having a defined MIME for WASM files.

The 'Content-Encoding` support depends on the web browser, if the web browser does not support it then it can not be used. For wasm I expect a user defined (custom) decoder, one that might be specific to a app and have no public standard. Even without such a custom decompressor I expect a translator between the received and decompressed data and the input to the target compiler, to do things like macro expansion, and this blob might again have an encoding that is not a public standard or that warrants a specific MIME type. I am not blocking anything, just trying to get some perspective on what the MIME type represents.

@wllang The WAST file format is an example of what you describe: it's not a valid WASM file by itself, but it can become one after being processed. For something like that, to avoid compatibility risks, you'd use a different MIME type (like text/webassembly), the last-resort application/octet-stream, or even no Content-Type header at all (it's not required by the HTTP standard).

@Kardax Yes, great example, thanks. We could have a translator that accepted the wast text format and converts it to the wasm binary format for compilation. I was thinking of other binary formats, but you raise a really good example that might be interesting for some small development or training uses. So in https://github.com/WebAssembly/design/issues/982 I would like to see it be possible to submit the text file as an input, plus a description of the translator, to make that work.

@annevk / @domenic I think you were discussing this?

Yes, someone needs to add the MIME type check to the compileStreaming/instantiateStreaming spec in JS.md...

I think you mean in Web.md which already has this requirement. I think this issue is about renaming the MIME type subtype from "wasm" to "webassembly" though it's not entirely clear from OP.

@annevk ah gotcha. Sounds like we can close then, if it's just a rename at this point?

@jfbastien if you don't want to rename it from "wasm" to "webassembly", yes.

Well, isn't this already shipping in Chrome or about to ship? IIUC it's hard to change at this point, and I don't see much upside from one name to another.

Closing for now, happy to reopen if I was wrong.

@annevk , @jfbastien At the time I wrote this issue, the MIME hadn't yet been publicly decided as application/wasm. I wasn't aware that there was already considerable momentum behind that choice (relatively little of the team's activity is published). I don't have a problem with the decision 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

badumt55 picture badumt55  路  8Comments

void4 picture void4  路  5Comments

chicoxyzzy picture chicoxyzzy  路  5Comments

cretz picture cretz  路  5Comments

nikhedonia picture nikhedonia  路  7Comments