Repository navigation
Define link processing for prefetch - #8111
Conversation
domenic
left a comment
There was a problem hiding this comment.
Well, this is certainly simple; I have no qualms with the algorithm. However:
Already implemented
seems unlikely? My understanding is there's a lot of non-interop on prefetch from various implementers, and nobody currently implements this proposal exactly. Or maybe Firefox does, and that's why they're N/A for the bug link?
The Safari bug seems to be about something that isn't captured in this spec proposal. If we don't want to allow prefetch during loading, that should be normatively enforced.
The Chrome bug seems to be about removing the 5-minute rule, but are there more things Chrome does, e.g. use a memory cache, special treatment of other headers besides max-age, etc. which also need bugs?
| </ol> | ||
|
|
||
| <p>The <span>process a link header</span> steps for this type of linked resource are to do | ||
| nothing.</p> |
There was a problem hiding this comment.
This is a bit surprising to me. Tests would be good!
| to "<code data-x="">prefetch</code>".</p></li> | ||
|
|
||
| <li><p>Set <var>request</var>'s <span data-x="concept-request-initiator">initiator</span> | ||
| to "<code data-x="">prefetch</code>".</p></li> |
There was a problem hiding this comment.
There was a problem hiding this comment.
I don't think so. It's still implementation-defined.
|
|
||
| <li><p>Set <var>request</var>'s <span data-x="concept-request-initiator">initiator</span> | ||
| to "<code data-x="">prefetch</code>".</p></li> | ||
|
|
There was a problem hiding this comment.
As noted in #5229 I guess we should add some headers? But which ones? See https://wicg.github.io/nav-speculation/prefetch.html#prefetch-algorithms step 5 for what nav-speculation is doing. It includes a carveout for vendor-specific headers which I dislike but decided was OK back in WICG/nav-speculation#133 (comment) .
There was a problem hiding this comment.
We already send Purpose: Prefetch. I think we should also send Sec-Purpose: Prefetch and have it as part of the spec.
There was a problem hiding this comment.
Should we allow/encourage/require Purpose: Prefetch? What about X-moz: prefetch or X-Purpose: preview? Those latter two values were tested, I think, for things besides <link rel="prefetch">; do you know what Firefox and Safari do for <link rel="prefetch">?
There was a problem hiding this comment.
I think currently we're specifying as Sec-Purpose: Prefetch, and everything else is proprietary and UAs will probably keep it for backwards compat.
There was a problem hiding this comment.
I would hope they plan on removing the non-compliant headers. If the plan is that everyone ends up with multiple incompatible headers that does not seem great and at that point there's no real value in using Sec- either, right?
Actually Safari implements this exactly. Firefox have an intricate way to de-prioritize prefetches, i.e. performing them one by one and only after the window onload event is fired. I wonder if this needs to be interoperable, or if this can be considered as their implementation of determining request priority.
I referenced this bug because the bug mentions that prefetch is not entirely spec'ed yet.
From what I understood, the special treatment is for navigations, which would be ported to nav-speculation in due time. But I'll double check. Regarding using the memory cache, it feels more of an optimization, I'm not sure it's observable in any way. |
commented
Jul 21, 2022
OK, so they should probably wontfix https://bugs.webkit.org/show_bug.cgi?id=49238 then?
It feels like a bit of a stretch, but, maybe it's OK, given how vague priority is. My main concern is that if there are patterns that browsers should follow to conform to websites' expectations and usage, then we should try to encode that, so that browsers implementing the spec naively don't end up causing sites to perform poorly in their browser. It's not clear to me whether or not that's the case.
My understanding was that the memory cache prevents future fetches from hitting the network and/or service worker, which would otherwise do so. I might be wrong. Also a crbug comment from 2013 indicates that whether or not |
commented
Jul 21, 2022
I think they should consider how they implement fetching priority if it bothers their users. But perhaps it's not a spec concern.
I agree with that. I wonder if this can be done incrementally.
Right, so a test can be written that checks if consuming a disk-cachable prefetch has hit a service worker. Will give it a go.
I believe it should definitely not block the load events. In Firefox it wouldn't even take place before the load event. I will check what WPTs tell us. |
I checked this. The prefetch cache in chrome is actually some special consideration about when to invalidate, but it's really the regular disk cache. It doesn't prevent SWs from running again on the same resource. |
commented
Jul 22, 2022
|
#5229 (comment) discusses even more departures that Chrome has from this proposed spec: some special behavior for as=document that allows it to be used to speed up cross-site navigations. I am a bit frustrated that was not mentioned either in the implementer support section. Are we planning to remove that in Chrome? If not then I think it would be bad to move forward with this spec proposal which specifies something so different... |
commented
Jul 22, 2022
Yes, the idea as I understood it was to move the as=document things to nav-speculation. I didn't mention it because I wanted to specify the common-denominator first, and then discuss the "chrome only" bits and see what of it needs to stay in . What frustrates me is that it's terribly difficult to get people to join this conversation over something that's implemented differently in each browser and not specified... Could use some help with that. |
commented
Jul 22, 2022
|
Well, it seems like we might have a good basis? If Safari matches this PR, and Firefox maybe matches it except for some stuff about load timing which we think is OK, then Chrome is the odd one out, right? We don't really need that much of a conversation; we just need Chrome to commit to matching the other two browsers. To be clear, I don't think interpreting Chrome's current implementation as a superset of this PR is a great application of the WHATWG working mode. "Yes, we implement this PR but also a bunch of other stuff triggered by the same link rel" would justify a lot of weirdness, if we extended that rule more broadly. We could just merge this on the basis of Firefox + Safari support, saying we don't know Chrome's position on it, but (a) that's a weird thing for two Chrome engineers to conclude 🙂 and (b) if there's a chance that Chrome wants to actually steer the semantics of rel=prefetch toward something other than what's in this PR in the future, then it feels like this PR is a bit deceptive, especially for Firefox + Safari engineers who might think it indicates an agreement on a specific behavior, when in reality it doesn't. |
commented
Aug 27, 2022
Update: restrictive prefetch ( |
|
That sounds good. Here are some things we should be sure to test:
Once we have those test results, we can know exactly how far everyone is from the proposal, and confirm that everyone is on board with making the necessary changes. |
commented
Aug 29, 2022
https://bugs.chromium.org/p/chromium/issues/detail?id=1357407 |
commented
Aug 30, 2022
|
I dug deep into I propose the following:
|
In spec land, I think this is the same as when fetching with (To be clear, we don't need to solve that entire issue before proceeding here, but I want to get a sense of what the intent is, and maybe encode it in the spec and tests if we can do so despite the shaky foundations.)
(Assuming you mean "Consuming a prefetch" just means "making a fetch", right? A fetch that will hit the HTTP cache that the prefetch might have populated? I'm not sure it's a good idea to start selectively ignoring If there is significant evidence of |
Not sure yet, still investigating. It needs to tell the server which mime types the user agent supports and do some intricate content negotation thingies like SXG quality, and OTOH be ignored by the client HTTP cache.
Yes, of course :)
Yes.
Well it's a subset of Chromium's current "5 minute rule" for prefetches, which would be the precedent. I think the alternative to doing this would be to deprecate |
Done.
Updated the OP. Still need to figure out if what we do here with |
commented
Aug 30, 2022
When people use a library to prefetch HTML (which allows speeding one’s website very easily), like my library instant.page, or quicklink/Flying Pages/etc., they expect it to just work and generally don’t know jack about caching headers. Even if they know they don’t have those conflicts in their head. Caching conflicts with prefetch are always a bad surprise in general. In the wild, Shopify uses Vary: Accept, causing problems. That’s a lot of sites where people just can’t set “correct” caching headers to let prefetch do its magic. I think standardizing ignoring Vary: Accept would be a great way to ensure in the long term that various changes to browsers' Accept headers don’t make a collateral damage of prefetch. |
It's actually the same as when fetching a document (iframe/window.open etc). You can prefetch anything that your browser can load. So I suggest to add Looking at whatwg/fetch#274 that switch statement is anyway far from useful, but understanding now that |
commented
Aug 31, 2022
|
@emilio @sefeng211 @bdekoz: Gecko thoughts? Trying to make prefetch interoperability less insane so please pitch in :) |
left a comment
There was a problem hiding this comment.
Looking pretty solid, assuming we can get cross-browser agreement... the test results are somewhat grim though! https://github.com/web-platform-tests/wpt/pull/35707/checks?check_run_id=8191297010
left a comment
There was a problem hiding this comment.
So as I understand it this essentially makes prefetch a way to fill the HTTP cache, with some special request headers and optionally some priority adjustments.
(This means that service workers will still be consulted.)
Chatting with colleagues that seems like an acceptable model.
| link request</span> given <var>options</var>.</p></li> | ||
|
|
||
| <li><p>Set <var>request</var>'s <span data-x="concept-request-initiator">initiator</span> to | ||
| "<code data-x="">prefetch</code>"..</p></li> |
Done in whatwg/fetch#1576 |
Prefetch is simply a fetch with `prefetch-src` CSP and no post-processing of the resource. Closes whatwg#5229
Prefetch is simply a fetch without post-processing the resource, and with a special header:
Sec-Purpose: Prefetch, which would be added in the Fetch-Metadata spec. See that issue for use-cases for the special header.Closes #5229
Closes w3c/resource-hints#86
Closes w3c/resource-hints#74
Closes whatwg/fetch#1008
At least two implementers are interested (and none opposed):
Sec-Purpose: HeaderTests are written and can be reviewed and commented upon at:
prefetch-srcis already testedImplementation bugs are filed:
1345207: remove the five minute rule
1358419:
Sec-Purposeheader626081: issues with
Accept801561: Prefetch src
1352371: Remove as=document special treatment
1457204: CSP prefetch-src
1788167: Align prefetch with spec
(See WHATWG Working Mode: Changes for more details.)
/infrastructure.html ( diff )
/links.html ( diff )