-
Notifications
You must be signed in to change notification settings - Fork 24
Specify processing model in terms of Fetch #86
Comments
@yoavweiss, is this on your plate, perhaps as whatwg/html#4115? |
Prefetch processing is on my plate: whatwg/fetch#881 and whatwg/html#4115. I plan to update the HTML PR this week. |
/cc @noamr |
My current action plan based on this discussion:
This would make a clear distinction between preload & prefetch:
|
I've researched how implementations handle prefetch today. I can spec something but because implementations do things very differently, it would be better to reach a consensus first.
const cache = new WeakMap();
function prefetch(link) {
for (const l of document.querySelectorAll('link')) {
if (cache.has(l)
return cache.get(l);
}
cache.set(link, fetch(link.href));
}
const prefetchQueue = [];
let prefetching = false;
function prefetchNext() {
prefetching = true;
if (!prefetchQueue.length)
return;
const links = prefetchQueue.pop();
fetch(links[0].href, {internalOptions: { priority: 'low' }})
.then(() => links.forEach(l => .dispatchEvent('load')))
.catch(() => links.forEach(l => .dispatchEvent('error')))
}
function prefetch(link) {
for (const p of prefetchQueue) {
if (p[0].href === link.href) {
p.push(link);
return;
}
}
window.prefetchQueue.push([link]);
if (prefetching)
prefetchNext();
}
window.addEventListener('load', prefetchNext);
function prefetch(link) {
fetch(link.href, { internalOptions: { priority: 'low', remainInCacheWithoutValidationMinutes: 5 }})
.then(() => { link.dispatch('load') })
.catch(() => { link.dispatch('error') })
} So to summarize:
I believe that we should reach a consensus about making the above table interoperable - otherwise |
Straw-man proposal for prefetch behavior:
|
This is something I tried to tackle when running into priority issues, but it got push back due to the possibility of regressing certain usage patterns. Might be worthwhile to take a second look and try to gather data. |
It's also possible to say that the definition of "low priority" can be UA-specific, and leave only the other 3 options (fire events, coalesce requests, remain in cache without validation). I believe those 3 need to be specified to reach any kind of interoperability with prefetch, with the |
This was discussed as the WG call. Notable comments/conclusions:
|
Another proposal, alternative to the chromium 5-minute rule: |
/cc @bdekoz @yutakahirano @achristensen07 @sefeng211 for opinions on the latest proposal. |
To move things forward, I created a strawman HTML PR in that spirit: whatwg/html#7693 |
I'm trying to understand the current landscape a bit better. #86 (comment) is helpful for some detailed issues but I lack a higher-level picture. Some questions:
|
Speeding up the next navigations by loading some of its subresources in advance. But probably some more specific data would be useful here.
Currently prefetch is a low priority fetch into the regular HTTP cache. In Chromium it survives in the cache for 5 minutes without validation. So it survives across navigations but not across origins (double-keyed etc).
Preload only works for current document.
It makes prefetch only work for subresources across same-origin navigations. |
So it works for same-origin navigational fetches too, right? Not just subresources? What about in other browsers; what use cases does it work for today in them?
Could it be used to speed up navigations of double-keyed subframes? E.g. if I do |
Yes, that use case overlaps somewhat with nav-speculation.
This was actually introduced in Gecko, and the Mozilla-specific FAQ talks about roughly the same use-cases. @bdekoz can perhaps shed more light. There's a lot of conversation here about how WebKit sees the feature.
Right. |
Yeah, I wasn't aware had been so widely evangelized for subresources (I'd mainly read articles advocating its use for documents). Alexandre's comments on the WebKit bug, for instance, are surely related to instant.page which injects them for document URLs. If we leave such use cases in the cold here, it'll regress those sites and at a minimum benefit from a migration path to something suitable for navigations. Do you know offhand if we have any way of distinguishing these in It feels like this should end up behaving at least similarly to Link rel preload headers discovered in the process of a navigational prefetch, which necessitates some form of further integration at least. By the way, I'm not sure whether we care, but technically there's also a fun edge case if a resource is |
True, It was originally more evangelized for documents. But with partitioned cache a lot of those sites in the cold have already regressed.
There is no
Right, they should behave somewhat similarly. But it should also behave similarly to how it is today - adding it to the HTTP cache and maintaining it there for a while (5 minutes in chrome, I propose: until the next same-origin navigation).
True, though only with |
Considering checking what sorts of MIME types are typically seen in link rel=prefetch responses to contextualize this. |
Even in UAs with partitioned cache, same-site documents still work today, no? |
It isn't obvious what sort of resource this is typically used to prefetch, and getting a rough estimate of this data from the field would be helpful in understanding how this feature is used and how it can be specified and evolved. Some uncertainty arose in w3c/resource-hints#86 Change-Id: I62d7e37c60aef7b5072d440a697642bfbe3816fd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3546102 Reviewed-by: Ian Clelland <[email protected]> Commit-Queue: Jeremy Roman <[email protected]> Cr-Commit-Position: refs/heads/main@{#984502}
Well firstly I think there is at least a case to be made for site (because that's how partitioning works). Secondly, nit it's not just |
I ran an HTTP Archive query to cross-cut
Results:
A random example from HA for a page that prefetches JS: |
May be interesting to look into caching as well (similar to this past query) |
Adjusting for cache, the numbers are similar and about 90% of the responses are cacheable. |
@yutakahirano - given @noamr's numbers here, would it make sense for Chromium to simplify the caching implementation around non-cacheable prefetches? Would it be worthwhile to add counters for cases where such a non-cachable resources are used? |
It isn't obvious what sort of resource this is typically used to prefetch, and getting a rough estimate of this data from the field would be helpful in understanding how this feature is used and how it can be specified and evolved. Some uncertainty arose in w3c/resource-hints#86 Change-Id: I62d7e37c60aef7b5072d440a697642bfbe3816fd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3546102 Reviewed-by: Ian Clelland <[email protected]> Commit-Queue: Jeremy Roman <[email protected]> Cr-Commit-Position: refs/heads/main@{#984502} NOKEYCHECK=True GitOrigin-RevId: 5d98fbfd97bb9d589364a22ce29b41f714bbc492
Prefetch is simply a fetch, which populates the HTTP cache, with no post-processing of the resource and with a special header Sec-Purpose: prefetch. (The latter is specified in whatwg/fetch#1576.) Closes #5229. Closes w3c/resource-hints#86. Closes w3c/resource-hints#74. Closes whatwg/fetch#1008.
I thought we had a dedicated issue for this in this repository, but I can't find it.
#63 and #66 are related though.
The text was updated successfully, but these errors were encountered: