-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<nomodule>, or other patterns for loading both classic and module scripts? #1442
Comments
I like a new attribute on
Do you think we will need a "nomodule2" attribute in the future? If yes, maybe we should make the classic script not run only if the value is the empty string, so we can add |
We shouldn't need versioning for modules. I agree that an element seems problematic, both for the reasons Simon states but also because you could not place it inside |
Good points against an element from both of you. I don't think we'll need For example |
Or |
This looks like optional loading of scripts based on feature detection, exclusively. The fact that we want to check for support for modules is just a case, but it could be anything else at this point. Therefore, wouldn't it be better to have a generic solution for including/excluding scripts based on any feature? Something like |
That kind of generic feature proposal is exactly what I was afraid this would snowball into :(. No, I don't think there's any interest in working on such a general-purpose feature (e.g. specifying what all the features on the platform are). |
I was sure that was the reason for that, which is indeed understandable. Couldn't the specs for this be developed in separate phases - first the general feature proposal with an "empty" list of features and then leave it open for proposing features to be included in a "per request" base? I don't think an extensive and comprehensive list is a must have. But I understand that this may be scary. |
APIs to test support for features don't work so well on the Web.
|
If a browser launches with Given that, apologies for bikeshedding. Having |
This allows selective delivery of classic scripts only to older user agents. Fixes #1442.
This seems like a useful feature, but I would be incredibly weary of pushing something out too quickly with a sense of urgency, that doesn't actually solve real problems. To dissuade the sense of urgency, I just put together a production-suitable bootstrap workflow for exactly this sort of thing at https://github.com/guybedford/isomorphic-browser-modules. The above project uses the same script file as both a module and a script to do its bootstrap, which in theory covers exactly the same need that the To really tackle the feature detection problem though, it is about ensuring it is possible to detect practical features that developers would want to provide. I've included my learnings below from the process:
I do hope we can value the fine-grained control of specific feature detection over blunt hammers here. Surely these lessons have been learnt enough times. |
That's not a reason to coalesce requests though. There's no standardized coalescing of requests at the moment. In fact, any browser that did would be non-conforming.
See #1013. |
@annevk thanks for the clarifications. I wasn't aware of that, I just assumed that there would be some coalescing and cache sharing between fetch implementations. Does this mean we will also need an |
@guybedford I think you should be able to use |
Apologies as it's off-topic, but I'd hope we could have a more definite story on preload. Unfortunately I can't test this as neither Edge or Safari supports it still. Having across-board preload support for deep module dependencies is really important to allow traditional (non-PUSH) server workflows for modules. |
I shouldn't have said "I think". |
To distill my argument above, I would suggest clarifying that the This is because Ideally |
This allows selective delivery of classic scripts only to older user agents. Fixes #1442.
This allows selective delivery of classic scripts only to older user agents. Fixes whatwg#1442.
At BlinkOn @paulirish and a Facebook dev (Paul, do you have his GitHub handle?) were asking about how to ship down both classic scripts for old browsers and module scripts for new browsers. The idea is to ship pure ES6 code with a module graph for new browsers, and a transpiled bundle of code for older ones.
One idea here is to introduce
<nomodule>
element (analogous to<noscript>
). Then you would write:Alternately a more targeted fix would be a
nomodule
attribute on<script>
:An alternative involving no new elements or attributes is to use JS-based feature detection, e.g.
However this will defeat the preload scanner (in the older browser case). You could try to work around it with
<link rel="preload">
but then you'd fetch bundle.js even in newer browsers which is sad.(EDIT: also, the above won't work because module scripts execute at "defer time"; we also would need to defer the evaluation of the above script, perhaps by listening to DOMContentLoaded.)
A third alternative is user-agent sniffing, of course.
Thoughts? Alternate ideas or patterns?
(Note: at first I thought
<noscript type="module">
would work but it clearly would not because an old browser which does not support modules would just see it as a normal<noscript>
and not execute the script-loading code inside.)/cc @whatwg/modules
The text was updated successfully, but these errors were encountered: