-
Notifications
You must be signed in to change notification settings - Fork 141
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
[worklets] <script> tag import feature design. #376
Comments
This seems bad since it will run the code in the main page context if the browser doesn't support worklet="". To avoid that you'd need a new type (e.g. type="paintworklet" or similar). I think it might also be better to use |
From OP it seems they want to have inline scripts as well. But yeah, rather than a new worklet attribute the easiest seems to just put it all in type. It's nice that worklets are already JavaScript modules so we don't need that extra dimension here. |
Yes, inline scripts are desirable if html modules get off the ground again, e.g. if this was used inside the <paper-ripple> web component: <!-- paper-ripple.html web component file -->
<link rel="import" href="../polymer/polymer.html">
<script type="paintworklet">
// code specific to the paper-ripple web component...
</script>
<template>
<div id="foo"></div>
</template>
<script>
// actual web component code....
</script>
|
@nyaxt might have thoughts as well. |
I think it'd be pretty bad to have inline scripts that run in a different global. |
Can you explain your reasoning here? My concern if we don't allow this is that web developers will simply polyfill this themselves, e.g. <!-- inside the page or web component file -->
<script id="code" type="paintworklet">
/* some large complex paint worklet code goes here */
</script>
<script>
const blob = new Blob([document.getElementById('code').textContent]);
await CSS.paintWorklet.import(URL.createObjectURL(blob));
</script> Which is bad for performance (duplicates a bunch of memory), etc, hence to provide this natively. |
@domenic really? We've had the exact same requests for workers in the past. Which also still seems fairly reasonable. |
(What @bfgeek sketches above is what I've seen for workers as well. It just hasn't surfaced enough for anyone to start caring.) |
From implementor + spec reader POV, using However, from pure mark-up perspective, I can also be convinced that |
It just seems very strange to me to have scripts like <script>
self === window;
document.addEventListener(...);
</script>
<script type="module">
self === window;
document.addEventListener(...);
</script>
<script type="paintworklet">
self === window; // fails, window is undefined
document.addEventListener(...); // fails, document is undefined
</script> all in the same source document. Maybe there is no better option; after all the HTML parser makes it very hard to have any new element contain unstructured data like In other words, this seems to be a request to reuse the parser behavior of If this feature is mostly related to HTML modules, then I'd suggest feeding this back into the discussion there, as it may inform the design there (e.g. using a different HTML parser or different format that isn't HTML as the container). |
I see your point @domenic, and that is indeed weird. From a developer’s perspective all I care about is being able to bundle components into a single file with markup, script, styles, worklets et al. If we can achieve that by feeding that back to HTML modules, then I’m all for that. |
The CSS Working Group just discussed Worklets, and agreed to the following resolutions:
The full IRC log of that discussion
|
Let's consolidate this and the other related issues into whatwg/html#6073. |
From feedback in various forms there was desire to have a declarative way to import scripts initially.
A simple proposal for this would be:
All other attributes would work as expected, e.g. "async", "defer", "nonce", "integrity" have the same behaviour as modules.
(For "async" in particular it'll spin up a global scope, and import the script before the document has finished parsing).
"crossorigin" would be the special one for the moment, which would be forced to "omit" until we decide if we should have cross-origin support.
The text was updated successfully, but these errors were encountered: