-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Forking from whatwg/html#443 (comment) and the next two comments
Can you say more? Why?
src
has an established meaning for web developers, having to do with URLs, not module specifiers. Breaking that mental model is not really acceptable. For example, <script src="jquery"></script>
fetches http://example.com/base/url/jquery
; <img src="jquery">
fetches http://example.com/base/url/jquery
; and so <script type="module" src="jquery">
must also. But see below, maybe I didn't quite understand what you meant...
More concretely, an inline module (no src attribute) would go through the loader starting at the translate hook; an out-of-band module (with src attribute) would go through the loader starting at the fetch hook. IOW the point of my PS above was that both inline and out-of-band <script type="module">s should go through the loader.
HMMM. Overall this seems reasonable. A few things:
- Did you intentionally omit resolve? So resolve does not apply to src? That is good. That means src at least uses URLs, not module specifiers, solving my top complaint. (If you want to intercept resolve, then my suggestion of a second attribute comes in. Or just use
<script>System.loader.import(...)</script>
; it seems about the same number of characters.) - The way of overriding the default fetch behavior in the browser is to use service worker. Adding a second way of intercepting fetches to the web platform---which runs on the main thread, no less---is going to need a lot more discussion. Maybe that is a separate issue for the browser loader spec to work out, but it's a big one that I haven't seen an issue for yet. Heck, maybe you set up the browser loader inside your service worker, using specialized APIs on the FetchEvent to pass it to a loader instance, or something.
- Running translate and instantiate on all
<script type="module">
s makes sense. It's basically building a framework into the browser for allowing custom execution of<script type="text/x-transcode-me">...</script>
to be built by supplying two functions (translate/instantiate). This framework is the high-level API that would normally have to be expressed using mutation observers + shadow DOM + some probably-complicated dependency management logic, as-is done today. If there's implementer interest in building a framework for this use case, then translate/instantiate on<script type="module">
seems like a reasonable path (although again, maybe service workers would fit more with the platform, since that's where people will be transcoding multimedia and other response bodies).
Let me try to say it a little differently: my principal concern with not allowing the loader to participate in the hooking of script/module tags is that <script type="module"> becomes an incomplete story for how to kick off an app. Devs would need to learn that if they want loader integration, they have to write a top-level wrapper script. And if that's the case, then <script type="module"> is less universally reliable than just always kicking off apps with dynamic APIs, à la:
Yeah, I get that, at least for apps which need to globally customize translate/instantiate behavior.
On the other hand, I'm not sure <script type="module">
is really aimed at developers who want custom loaders. I would think such developers would, well, use their custom loader. That is, you seem to be proposing that such developers will do:
<script>
System.loader = class JSXLoader extends System.Loader { ... };
</script>
<script type="module" src="foo.jsx"></script>
<!-- or is it loadfromspecifier="./foo.jsx"? -->
whereas it seems more likely to me that they will do:
<script type="module">
const jsxLoader = new class JSXLoader extends System.Loader { ... };
jsxLoader.import("./foo.jsx");
</script>
or perhaps
<script type="module" src="https://cdn.example.com/jsx-loader.js"
data-start="./foo.jsx"></script>
which is just generic sugar for the above, given a sufficiently well-written jsx-loader.js. This seems more compositional, messing with less global state, and more transparent as to what's going on; it only affects the module trees you explicitly import that way. It seems more likely to work in a world of third-party scripts.
What do you think?