-
Notifications
You must be signed in to change notification settings - Fork 118
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
<script type=webundle> should fire a load (or error) event? #697
Comments
cc: @felipeerias |
As a workaround, until we can have a consensus, users can try to fetch a (small) subresource immediately after inserting the script element into a document. For example: const script = document.createElement("script");
script.type = "webbundle";
script.textContext = JSON.stringify({ .... });
document.body.append(script);
fetch(a_tiny_subresource_in_bundle).then((_) => {
// Alternative of a load event listener of a script element
}).catch((error) => {
// Alternative of an error event listener of a script element
}) I'm not 100% sure whether this workaround is always applicable, however, this is fine in most cases. Any ideas or opinions are welcome! |
One thing I'm a little confused about, what do you mean by 'it fetches a bundle many times in its lifetime'? Our intention was that each bundlepreload section would result in a single request with a Bundle-Preload header; there would be no additional Bundle-Preload requests from the script element. After the page has sent a Bundle-Preload request, regular, non- To review:
In my mind, then, it might make sense to send:
The load event would be separate from the load events sent by later references to the bundled resources, which would not be sent from the script element. What do you think? Does that match the behavior of other script type elements? I'm not familiar with speculation rules, but I'll take a look. |
If resources can be served from the bundled response before the whole bundle has been received, then it would be possible for this to fire a load event but the bundle itself to fire an error event - I don't know if that's good or bad. Otherwise, I think it would be a perfect workaround. Perhaps another subresource with less overhead than a script could be a little faster and more accurate for timing, but it probably doesn't matter much. |
Basically, |
Got it, thank you for clarifying! It seems then like the first event I proposed should go to |
Thanks for the comments! It seems what we want to do is:
This sounds reasonable to me at first glance. At least, this would be consistent with the direction at whatwg/html#6421. @hiroshige-g |
Yeah, and I suppose defining "bundle loading failed" sub-cases is still a bit up in the air / might depend on bundle-preloading semantics. We can explore further what that is separately from the question of whether to fire the event, what do you think? |
Agreed. I guess defining "bundle loading failed" might be tricky on the bundle-preloading case. So we can explore that further as another issue. |
What should occur when:
IIUC Step 3 doesn't trigger new network request to |
A good question. For those who are not familiar with the context, see the requirement 2 of
Yeah, step 3 doesn't trigger new network request. We've not decided the behavior for failed cases. Let's assume step 3 doesn't trigger new network request for a failed case too. Given this assumption,
I don't have a strong preference. The behaviors of the Step3 would be one of the followings?
Either |
+1 to A. I don't like C and D. From the user's point of view, it is difficult to use if it's not guaranteed that either load or error will be fired. |
+1 to A. It is consistent with other cases where we fire load (and error) events without any fetch requests due to caching in the HTML spec layer:
Also it would keep the invariant of
Yeah, whether we reuse the failed cases or not is a separate issue to be determined. |
For bundle-preloading, step 3 depends on the contents of the element. If the resources specification contains new resources, a new request would be issued and a new load event should be fired. For consistency, I'm uncertain whether it'd be better to fire an event or not if no new resources are requested. Sorry for the delay, have been busy with other things - will be around more starting in ~two more weeks. @felipeerias can clarify further while I'm out! |
My spec PR #721 fires load/error events for every |
The main issue is #670.
It's unclear whether
<script type=webbundle>
should fire aload
(orerror
) event or not.And if they should be fired, when should
<script type=webbundle>
fire them?source
is loaded?For references, the other
<script type=>
-ish elements' behaviors are:Neither
<script type=importmaps>
nor<script type=speculationrules>
fires aload
event for an inline rule.Bundle Preloading doesn't mention when to fire a
load
event yet?I think it is non-trivial because it fetches a bundle many times in its life time.
We might want to align the event semantics of
<script type=webbundle>
with Bundle Preloading so that we can converge them in the future.The text was updated successfully, but these errors were encountered: