ResourceLoader now supports scripts written in modern JS format via the new es6 option in module definitions. In the same vein, I'd like to propose doing the same thing for <script type="module">.
Support for ES Modules is pretty widespread at this point. In terms of our own Grade A browsers, the only blockers would be Safari 9 and legacy Android Browser (4.x series). Safari 10 can be polyfilled (but does not support the <nomodule> attribute). We could manage the inconsistent support landscape with a config flag similar to es6: true (module: true perhaps).
Shipping module scripts has several immediate benefits:
- each module has its own isolated scope, so no more need to write IIFEs,
- "use strict" is always in effect
- module scripts are always deferred (same as the defer attribute), meaning that they are not blocking, load in parallel, and won't execute until the document is ready
- module scripts will always execute in the order they are placed in the document
- developers will benefit from better IDE tooling and will be able to write code in a more standardized way
Actual implementation of this change in ResourceLoader seems like it would be pretty straightforward (the RL client already appends a script tag for each module to document.head; telling it to add script.type = "module" for certain modules would not be too hard). But the bigger questions will of course concern the impact of such a feature on the larger MediaWiki ecosystem.
Thoughts?