Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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?


<p class="note no-backref">This can be used to allow the request to outlive the
<a>environment settings object</a>, e.g.,
<code>navigator.sendBeacon</code> and the HTML <code>img</code> element set this flag. Requests with
Expand Down Expand Up @@ -1947,8 +1950,8 @@ functionality.
<p>When a <a for=fetch>fetch group</a> is
<dfn export for="fetch group" id=concept-fetch-group-terminate>terminated</dfn>,
for each associated <a for="fetch group">fetch record</a> whose
<a for="fetch record">request</a>'s <a>done flag</a> or
<a>keepalive flag</a> is unset,
<a for="fetch record">request</a>'s <a>done flag</a>,
<a>keepalive flag</a>, and <a>speculative flag</a> are all unset,
<a lt=terminated for=fetch>terminate</a> the
<a for="fetch group">fetch record</a>'s
<a for="fetch record">fetch</a>.
Expand Down Expand Up @@ -3101,6 +3104,11 @@ the request.
<a for=request>origin</a> to <var>request</var>'s
<a for=request>client</a>'s <a for="environment settings object">origin</a>.

<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 for=/>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.

Copy link
Collaborator Author

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

Copy link
Member

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?

Copy link
Collaborator Author

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.

<li>
<p>If <var>request</var>'s <a for=request>header list</a>
<a for="header list">does not contain</a> `<code>Accept</code>`, then:
Expand Down Expand Up @@ -3138,8 +3146,9 @@ the request.

<li>
<p>If <var>request</var>'s <a for=request>priority</a> is null, then use <var>request</var>'s
<a for=request>initiator</a> and <a for=request>destination</a> appropriately in setting
<var>request</var>'s <a for=request>priority</a> to a user-agent-defined object.
<a for=request>initiator</a>, <a for=request>destination</a>, and <a for=request>speculative
flag</a> appropriately in setting <var>request</var>'s <a for=request>priority</a> to a
user-agent-defined object.

<p class=note>The user-agent-defined object could encompass stream weight and dependency
for HTTP/2, and equivalent information used to prioritize dispatch and processing of
Expand Down Expand Up @@ -4072,6 +4081,12 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b

<p>is true, and unset otherwise.

<li><p>If <var>httpRequest</var>'s <a for=request>speculative flag</a> is set,
<a for="header list">append</a>
`<code>Sec-Purpose</code>`/`<code>prefetch</code>` to
<var>httpRequest</var>'s
<a for=request>header list</a>.

<li><p>Let <var>contentLengthValue</var> be null.

<li><p>If <var>httpRequest</var>'s <a for=request>body</a> is null and
Expand Down Expand Up @@ -5628,6 +5643,7 @@ interface Request {
readonly attribute RequestRedirect redirect;
readonly attribute DOMString integrity;
readonly attribute boolean keepalive;
readonly attribute boolean speculative;
Copy link
Member

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?

Copy link
Collaborator Author

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).

Copy link
Member

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>?

Copy link
Collaborator Author

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)

Copy link
Member

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.

Copy link
Member

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.

readonly attribute boolean isReloadNavigation;
readonly attribute boolean isHistoryNavigation;
readonly attribute AbortSignal signal;
Expand Down Expand Up @@ -5787,6 +5803,11 @@ initially a new {{AbortSignal}} object.
<dd>Returns a boolean indicating whether or not <var>request</var> can outlive the global in which
it was created.

<dt><code><var>request</var> . <a attribute for=Request>speculative</a></code>
<dd>Returns a boolean indicating whether or not <var>request</var> is a speculative fetch, which
means it could be ignored by the user agent, have low priority, and can outlive the global in which
yoavweiss marked this conversation as resolved.
Show resolved Hide resolved
it was created.

<dt><code><var>request</var> . <a attribute for=Request>isReloadNavigation</a></code>
<dd>Returns a boolean indicating whether or not <var>request</var> is for a reload navigation.

Expand Down Expand Up @@ -5918,6 +5939,9 @@ constructor must run these steps:
<dt><a>keepalive flag</a>
<dd><var>request</var>'s <a>keepalive flag</a>.

<dt><a>speculative flag</a>
<dd><var>request</var>'s <a>speculative flag</a>.

<dt><a for=request>reload-navigation flag</a>
<dd><var>request</var>'s <a for=request>reload-navigation flag</a>.

Expand Down Expand Up @@ -6210,6 +6234,10 @@ must return the <a>context object</a>'s <a for=Request>request</a>'s
must return true if the <a>context object</a>'s <a for=Request>request</a>'s <a>keepalive flag</a>
is set, and false otherwise.

<p>The <dfn attribute for=Request><code>speculative</code></dfn> attribute's getter, when invoked,
must return true if the <a>context object</a>'s <a for=Request>request</a>'s <a>speculative flag</a>
is set, and false otherwise.

<p>The <dfn attribute for=Request><code>isReloadNavigation</code></dfn> attribute's getter, when
invoked, must return true if the <a>context object</a>'s <a for=Request>request</a>'s
<a for=request>reload-navigation flag</a> is set, and false otherwise.
Expand Down