-
Notifications
You must be signed in to change notification settings - Fork 330
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
Add a speculative flag to Request
as well as related processing
#881
base: main
Are you sure you want to change the base?
Conversation
@annevk - any advice on how such language can be formulated? |
Reqeust
as well as related processingRequest
as well as related processing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you could return early somehow for a speculative fetch. What does ignoring mean though? Not invoking fetch at all?
@@ -5628,6 +5638,7 @@ interface Request { | |||
readonly attribute RequestRedirect redirect; | |||
readonly attribute DOMString integrity; | |||
readonly attribute boolean keepalive; | |||
readonly attribute boolean speculative; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would only result in setting the header? You'd still get the response and such?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's the current intention. Even though prefetch
is destined for the next navigation, the current renderer can still get the response (e.g. onload
fires for it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, but this adds it to fetch()
as a new feature. Was that intended? Or should this only be accessible via <link>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it'd be needed to make those headers survive SWs (although that may vary based on where #880 ends up)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this would also allow creation. Surviving SW should happen based on copying private state I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^That sounds right to me. This is similar to the idea that priority
is a concept that gets preserved here but is never exposed to the Fetch API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing! :)
@@ -5628,6 +5638,7 @@ interface Request { | |||
readonly attribute RequestRedirect redirect; | |||
readonly attribute DOMString integrity; | |||
readonly attribute boolean keepalive; | |||
readonly attribute boolean speculative; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's the current intention. Even though prefetch
is destined for the next navigation, the current renderer can still get the response (e.g. onload
fires for it).
<li><p>If a <var>request</var>'s <a for=request>speculative flag</a> is set, then the user agent | ||
may <a for=fetch lt=terminated>terminate</a> the <a>fetch</a> and return an <a>aborted network | ||
error</a>, in cases where it's reasonable to believe it will result in better user experience. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@annevk I wasn't sure what to write here, so started by writing something. It feels a bit fuzzy to be part of the processing model, so advice on making it better would be appreciated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How concrete is it in the implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently I'm not aware of implementations that do that at the moment. When discussing whatwg/html#4115 @youennf wanted to give UAs the concrete possibility to do so, while staying conformant.
I added a step to the processing model, aborting early at the UA's discretion. I think it'd be better to notify the developer that prefetch is being ignored. |
Overall, I would tend to go with the minimum proposal to have a functional targeting navigation loads.
If we narrow down the scope of prefetch to navigation loads, we might be able to simplify things without loosing too much functionality.
We also do not want to have the prefetch load go to the SW of the future navigation page.
|
@youennf thanks for your comments! :) (and apologies for my slowness, travel is my typical excuse) Regarding 1-3, they are defined in whatwg/html#4115 Regarding 4 and 5, we can probably avoid those for the time being. The tradeoff here would be that prefetches would be somewhat magical, but maybe we can tackle that later? Regarding 6, agree that there's no need to communicate the actual response bytes to the prefetching page. Not sure how to spell that out as a spec concept though. |
To improve efficiency, a prefetch could also be allowed to consult the HTTP cache and/or prefetch cache. |
There are many cases where prefetch is used to load subresources. For instance, there are sites that will create a |
Subresources could potentially be optimized with link preloads in the prefetched resource or web packaging. |
Link preloads in the document are still a full RTT slower than prefetching the subresource at navigation start. |
Sure. In general though, it seems rather brittle for a page to try optimizing the loading of a cross-origin page that might change any minute. Also, if the subresource is already in the cache (say a JS library that is needed for all pages of the prefetched origin), that might actually slow things down to prefetch it if the subresource is already in the cache and prefetch is not allowed to look at the cache. |
Right. We'd need the prefetch to specify a cache key (destination origin) to use for the subresource, otherwise the prefetch could be wasted if the cache already has the resource |
@@ -1077,6 +1077,9 @@ explicitly set <a for=/>request</a>'s | |||
<p id=keep-alive-flag>A <a for=/>request</a> has an associated | |||
<dfn for=request export>keepalive flag</dfn>. Unless stated otherwise it is unset. | |||
|
|||
<p id=speculative-flag>A <a for=/>request</a> has an associated | |||
<dfn for=request export>speculative flag</dfn>. Unless stated otherwise it is unset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this should be a boolean, as I think we're leaning more towards explicit booleans as opposed to "flags"s these days?
Sorry, I meant to reply to this earlier. This sounds good to me. |
As discussed on w3c/resource-hints#74 and on whatwg/html#4115, this PR adds a speculative flag to
Request
, which makes sure the request:I intend (as part of whatwg/html#4115) to then make sure prefetch requests are sent with this flag set.
Preview | Diff