Add a speculative flag to Request as well as related processing#881
Add a speculative flag to Request as well as related processing#881yoavweiss wants to merge 5 commits into
Request as well as related processing#881Conversation
@annevk - any advice on how such language can be formulated? |
Reqeust as well as related processingRequest as well as related processing
annevk
left a comment
There was a problem hiding this comment.
I suppose you could return early somehow for a speculative fetch. What does ignoring mean though? Not invoking fetch at all?
| readonly attribute RequestRedirect redirect; | ||
| readonly attribute DOMString integrity; | ||
| readonly attribute boolean keepalive; | ||
| readonly attribute boolean speculative; |
There was a problem hiding this comment.
This would only result in setting the header? You'd still get the response and such?
There was a problem hiding this comment.
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.
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.
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.
But this would also allow creation. Surviving SW should happen based on copying private state I think.
There was a problem hiding this comment.
^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.
yoavweiss
left a comment
There was a problem hiding this comment.
Thanks for reviewing! :)
| readonly attribute RequestRedirect redirect; | ||
| readonly attribute DOMString integrity; | ||
| readonly attribute boolean keepalive; | ||
| readonly attribute boolean speculative; |
There was a problem hiding this comment.
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.
@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.
How concrete is it in the implementation?
There was a problem hiding this comment.
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 |
| <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.
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