DOM handler and import
Constellation opened this issue · comments
I'm not confident that this is the right place to discuss about it.
We can write the code for the handler in HTML, like,
<body onload="import("./a.js");"></body>
In that case, should we allow import
operator inside this handler?
If we allow it, I think we have no way to specify crossorigin
, nonce
etc. parameters for the subsequent fetching request for this import
operator.
How would you currently specify those parameters in a Script or a Module?
https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script
https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure
<script type="module" nonce="xxx" src="..."></script>
The above nonce
will be propagated through the module tree.
I believe this will be potentially in a second parameter, but in a future proposal. See #31
Sounds nice :)
Ah, I think still we need to define the default values for handler case (but the direction seems correct).
And we also need to decide whether we should support import
inside the handler onload="import(...)"
in HTML text.
https://github.com/tc39/proposal-dynamic-import/blob/master/HTML%20Integration.md shows the current plan for HTML integration, including the defaults.
I admit that I hadn't thought about the usage inside event handler attributes. But I can't see any reason to prevent them; they're just like any other classic script in this regard.
This is fully specified in HTML now, and web-platform-tests has some tests so far and more incoming once I fix whatwg/html#3116 (because I want to write tests for all these string-compilation cases at the same time).