-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Prefetching Documents #6723
Comments
I think this issue would be best opened on the spec that defines prefetch, which is https://w3c.github.io/resource-hints/ ? Although we do hope to one day move that spec into HTML for better maintenance. /cc @domfarolino @yoavweiss |
Happy to move it there if you like, though it was @yoavweiss who suggested I post it here ;) |
Thanks for filing this and continuing the discussion Jeff. Yeah, things are a bit nastily spread out at the moment, so I am pretty agnostic as to where this discussion takes place. Since we eventually want to consolidate all of this in HTML, here seems as good as anywhere I suppose. I'd love to here @annevk's take on this, but it seems like a good idea to me. Things can get a little tricky with the fact that the network partition key is a little under-defined. Right now your text makes the distinction between top-level and first-level-nested-iframe, and the network partition key has a top-level bit/key corresponding to the top-level site, however it has a currently implementation-defined second-key to represent partitioning at potentially arbitrary nesting levels. So it would be interesting to figure out exactly what behavior we want:
|
Normal usage is |
That's right, both (1) and (2) support a top-level A.com prefetching B.com, to be used for an iframe that is nested under A.com. And just to be clear, I am not recommending that we should consider supporting prefetching in one context at some level in the tree structure, and reuse by another context at another level in the tree structure. It's just that if the fetching-and-reusing context are nested at all, we begin relying on the implementation-defined parts of the network partition key, and therefore behavior would differ depending on whether or not a browser implements double-key caching, triple-key caching, and so on, compared to browsers that don't. |
I would say that Safari's behavior is a bug and likely the result of the prefetch cache not being double-keyed. @youennf can confirm. That might be why it's disabled. Chrome partitions by more than the top-level site and I would expect that's why you see what you see in Chrome. I don't think it's safe to give control over the partition key. The whole reason we have that is to keep things isolated. |
It seems like a good idea to express whether a Separately: this |
We could let people be explicit about what they want via an This would mean we would not need In the case where the |
In cases where browsers care about nested origins, we could allow |
So essentially that would give an attacker the ability to fetch a resource with an arbitrary authority. Something that's going to be only possible through new windows, once browsers have broadly shipped state partitioning. The resulting resource is just cached, but on the surface it seems like that gives attackers at least one additional side channel over the ones they have already available to them. |
Ultimately writing into an arbitrary partition right away does seem like something modern browsers would prefer to avoid. For main resources I've been thinking about prefetching without credentials and holding that separate from that site's real partition until the user actually navigates there. This at least means you can't write into arbitrary partitions without some user action that implicates that partition. (WICG/nav-speculation is where that work is happening) The case of wanting to prefetch a subresource for a future navigation seems even trickier, at least if the declaration is coming from the previous page as opposed to, e.g., the main resource's Link rel=preload response headers. Even with an isolated cache (and the potentially redundant fetches that implies) it allows sending data in more ways than a plain URL navigation would. It certainly seems like a hard case to allow while preserving isolation between partitions. |
I would tend to restrict prefetch to top level navigation only and rely on preloads for all other resources for which there is a known keying context. We probably need some experimentation with prefetching without credentials. @kinu, any insight? |
^^ @nyaxt |
I think this is OK. For the same document, preload is indeed similar to prefetch and redundant in some cases, where the difference is in priority - preload now vs. prefetch when idle. I like the |
Thanks. @kinu left the project, and @nhiroki and I are taking over.
I personally like this direction.
I'd like to explore |
Historically,
<link rel=prefetch href=url>
would tell the browser to consider fetchingurl
, and then if the browser neededurl
for anything it would be available. As browsers have changed how they fetch resources, however, this is no longer so simple. A browser with a partitioned cache typically has a different cache key forhttps://a.example
when it's a top-level page vs an iframe. When it sees aprefetch
, it needs to pick which key to use.This means
<link rel=prefetch href="https://a.example">
can support<iframe src="https://a.example">
orwindow.location='https://a.example'
but not both.Here are two demonstration pages with
<link rel=prefetch>
:Both prefetch, wait five seconds, then attempt to use the prefetched result. The first uses the prefetch to populate an iframe while the second uses it for navigation.
I tested on Chrome, Firefox, and Safari. (Safari normally doesn't respect link prefetch. This is with Develop > Experimental Features > LinkPrefetch on.) Here's whether the prefetch is used (no additional network request on the wire):
If we include
as=document
, Chrome does use the prefetch while Safari and Firefox ignore the attribute and behave as before:One way to fix this would be to allow sites to make their intention clear. The fetch spec has an iframe destination, so we could use that:
as=iframe
. Then we could specas=document
as being for top-level navigation only.The text was updated successfully, but these errors were encountered: