-
Notifications
You must be signed in to change notification settings - Fork 337
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
Integration with preload #1342
Integration with preload #1342
Conversation
@annevk I've revised this, whatwg/html#7260 would also need some changes to match, but I wanted to see that this is on the right track first. The idea is that preloads are matched before the fetch becomes parallel and overrides all the HTTP specific check as it's assumed they were done for the preloaded request. An alternative to doing things this way is to have the preload list inside fetch, and have the HTML spec add to it / clear it. This might make things easier in terms of future potential things like supporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I think this can work, but it will depend a bit on the other details.
I'm also not sure where the cache itself should be defined. I can see arguments either way.
Actually, I'm not sure. Doing a cache lookup synchronously seems bad, but perhaps that is what implementations do? That probably warrants a bit more investigation. One way to do it later in "main fetch" would be to check the value of recursive I suppose, although that might still run into problems with HTTP authentication requests. |
Cache lookup should be synchronous IMO as it relies on something controlled by the main thread, making it parallel would create either locks or unnecessary races. Maybe keeping it where I put it is correct? |
Check that preloaded resources are reused/ignored based on the parameters available to a preload link (href, crossorigin, as), and do not rely on other parameters (e.g. whether a script is a module). See whatwg/html#7260 and whatwg/fetch#1342
Check that preloaded resources are reused/ignored based on the parameters available to a preload link (href, crossorigin, as), and do not rely on other parameters (e.g. whether a script is a module). See whatwg/html#7260 and whatwg/fetch#1342
Check that preloaded resources are reused/ignored based on the parameters available to a preload link (href, crossorigin, as), and do not rely on other parameters (e.g. whether a script is a module). See whatwg/html#7260 and whatwg/fetch#1342
Check that preloaded resources are reused/ignored based on the parameters available to a preload link (href, crossorigin, as), and do not rely on other parameters (e.g. whether a script is a module). See whatwg/html#7260 and whatwg/fetch#1342
* Add tests to verify preload caching behavior Check that preloaded resources are reused/ignored based on the parameters available to a preload link (href, crossorigin, as), and do not rely on other parameters (e.g. whether a script is a module). See whatwg/html#7260 and whatwg/fetch#1342 * Add missing font * whitespace * Cleanup * PR nits * PR nits * More nits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this end up invoking finalize response?
fetch.bs
Outdated
<a for=request>header list</a>, if <var>header</var>'s <a for=header>name</a> is | ||
not `<code>If-Modified-Since</code>`, `<code>If-None-Match</code>`, `<code>If-Unmodified-Since</code>`, | ||
`<code>If-Match</code>`, `<code>User-Agent</code>`, or `<code>Cache-Control</code>`, set | ||
<var>hasCustomHeaders</var> to true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would always end up with hasCustomHeaders being true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come?
Anyway, maybe we should avoid hasCustomHeaders
at all, and Let fetch()
set allow preloads
to false if there are user-defined headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had misread it, but it also seems the requirement is different now. Any author-defined headers triggers it now. But doesn't that also apply to XMLHttpRequest
?
fetch.bs
Outdated
<li><p><var>request</var>'s <a for=request>allow preloads</a> is true | ||
|
||
<li><p><var>request</var>'s <a for=request>origin</a> is <var>request</var>'s | ||
<a for=request>client</a>'s <a for="environment settings object">origin</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this not be true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's theoretically possible to call fetch with a different origin, the only place where I found this to happen is Process a navigate fetch which is not relevant for preloads. Maybe this can be an assert?
fetch.bs
Outdated
<ol> | ||
<li><p>Let <var>onPreloadedResponseAvailable</var> be to an algorithm that runs the following | ||
step <a>in parallel</a> given <a for=/>response</a> <var>response</var>: | ||
Run <a>fetch finale</a> given <var>response</var> and <var>fetchParams</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping needs to be adjusted here. Run should be lowercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
fetch.bs
Outdated
<a>fetch finale</a> given <var>response</var> and <var>fetchParams</var>. | ||
|
||
<li><p>Let <var>foundPreloadedResource</var> be the result of invoking | ||
<span>consume a preloaded resource</span> for <var>req</var>'s <a for=request>window</a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use <a>
.
fetch.bs
Outdated
<a for=request>header list</a>, if <var>header</var>'s <a for=header>name</a> is | ||
not `<code>If-Modified-Since</code>`, `<code>If-None-Match</code>`, `<code>If-Unmodified-Since</code>`, | ||
`<code>If-Match</code>`, `<code>User-Agent</code>`, or `<code>Cache-Control</code>`, set | ||
<var>hasCustomHeaders</var> to true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had misread it, but it also seems the requirement is different now. Any author-defined headers triggers it now. But doesn't that also apply to XMLHttpRequest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would we expect to use "allow preloads"? If it's just XHR and fetch()
I think we have enough state on request to make that determination already.
Custom headers currently should disallow preloads, but also things like "synchronous XHR", which I don't know if we have the knowledge for at this point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, this depends on the other PR that merges everything into "fetch finale", right?
fetch.bs
Outdated
<p>If all of the following conditions are true:</p> | ||
|
||
<ul class=brief> | ||
<li><p><var>request</var>'s <a for=request>destination</a> is not "<code>document</code>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use https://fetch.spec.whatwg.org/#navigation-request instead? The only overlap I can see with mode is for embed/object. Otherwise this would be redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this line is wrong. It's ok to preload a document.
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
I don't think it needs to be dependent. Fetch finale clarifies things but doesn't change the behavior of this. |
@annevk: another review? |
…vior, a=testonly Automatic update from web-platform-tests Add tests to verify preload caching behavior (#31539) * Add tests to verify preload caching behavior Check that preloaded resources are reused/ignored based on the parameters available to a preload link (href, crossorigin, as), and do not rely on other parameters (e.g. whether a script is a module). See whatwg/html#7260 and whatwg/fetch#1342 * Add missing font * whitespace * Cleanup * PR nits * PR nits * More nits -- wpt-commits: ef427f550f2a2a803fb2fa0886951e559fc83d9c wpt-pr: 31539
@annevk: another review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-authoritative LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the changes I made look okay to you?
Sure! |
@noamr where is the work tracked on the "memory cache"? To some extent it was tracked as part of the preload issue before. |
What was tracked before is the relationship between preload and the memory cache. The way it is spec'ed now, the relationship with requests and preloads is simple - if the CORS-mode and URL match then the preloaded resource should be consumed, otherwise ignored (re-fetched). On WebKit and Gecko this is not the case (because of the "memory cache" the CORS mode is ignored) and I submitted a WPT and opened relevant bugs. I do believe the memory cache should be better defined, but it's not currently tracked. |
Filed #1400. |
@noamr could you link the bugs from OP? |
Not sure what OP is. |
It stands for original post(er) in a thread. |
Before any particular fetch steps are performed, see if there is a
matching request already in the preload store and consume it.
This is called from the main fetch to avoid race conditions.
Depends on whatwg/html#7260, and together they fix #590.
(See WHATWG Working Mode: Changes for more details.)
Preview | Diff
Preview | Diff