esm-integration icon indicating copy to clipboard operation
esm-integration copied to clipboard

(X)HTML import name suggestion

Open ghost opened this issue 5 years ago • 6 comments

Unless I am mistaken, it is currently being proposed that ECMAScript be able to use MJS syntax for imports, and (X)HTML to use a module script tag?

For the MJS part, I have no opinion, for the (X)HTML web page it is being suggested that we could use something along the lines of:

<script type="module" src="./main.wasm" />

If so, might I suggest that we look at how JavaScript was originally intended to be imported:

<script type="text/javascript" src="./main.js" />

Google's Dartium browser used the Dart mime for executing Dart:

<script type="application/dart" src="./main.dart" />

Thus, shouldn't we use the Wasm mime-type as the "type" in (X)HTML?

This would make it much clearer to the developer, be clearer to the browser, and be better compatibility-wise: older browsers would not attempt to request the file at all, only newer browsers would. Even a current browser would expect JavaScript, thus waste client resources just to error upon seeing Wasm bytecode.

Unless this proposal is purely for a more ergonomic syntax when used in modules.

ghost avatar Sep 20 '20 04:09 ghost

I believe that using:

<script type="application/wasm" src="./main.wasm" />

Is probably the best approach, given that WebAssembly files are always modules.

ExE-Boss avatar Nov 29 '20 11:11 ExE-Boss

I would assume that <script type="module">, should work for anything the browser knows how to import using esm.

devsnek avatar Nov 29 '20 15:11 devsnek

I would assume that <script type="module">, should work for anything the browser knows how to import using esm.

I could see that making sense, but would it be at least permitted to use the Wasm MIME type?

In my opinion, seeing the Wasm MIME is more readable, and others may find that it makes more sense too, but if we have to use module for everything, I guess that's fine too.

ghost avatar Nov 30 '20 00:11 ghost

Note that even with https://github.com/whatwg/html/pull/4372, <script type="module"> is only allowed to load JavaScript modules

ExE-Boss avatar Dec 01 '20 12:12 ExE-Boss

Note that even with whatwg/html#4372...

https://github.com/whatwg/html/pull/4372#issuecomment-735615603 It seems like someone had said that they would rather not see the WebAssembly MIME type used as the value of the type attribute.

ghost avatar Dec 01 '20 16:12 ghost

It seems like no progress has veen made here, so far? Imo, anything that allows clearly distinguishing WebAssembly from JavaScript would be beneficial, at least regarding readability of the document. On top of readability, using type="wasm"is slightly shorter than "module," thus more ergonomic, and would also help with file storing and serving documents over the network by being (slightly) more compact.

I do believe the situation that I had initially raised, that is, consumption of user resources in order to request Wasm, which a browser would always fail to load, is a valid reason to make the explicit distinction. Do the authors of the proposal agree?

On the other hand, if type="module" is what will be used, feel free to close the issue.

ghost avatar Jun 18 '21 13:06 ghost