Closed jakearchibald closed 10 years ago
You mean preload and not execute right? Because nothing stops you from using a regular script tag to load it - put it in the head, slap async on it, etc.
As it stands, my intent behind rel=preload
is to provide a declarative way to communicate with the preload scanner. Now, the interesting part is that while all modern browsers have one, none of them make any promises about when or whether it'll kick in - depends on page structure, available resources at runtime, browser flags, etc. That's why it reads as a "maybe" right now.
You mean preload and not execute right?
Yeah.
my intent behind
rel=preload
is to provide a declarative way to communicate with the preload scanner.
Does that mean…
var link = document.createElement('link');
link.rel = "preload";
link.href = "whatever.img";
document.head.appendChild(link);
…must not trigger a request, since it has no interaction with the preload scanner?
It may trigger a request. Note that in order to use the response you'll also have to inject an img
or send an XHR for it... in either case, there is more JS code. So, if you're scheduling a resource fetch for the current page, it's not clear to me why you wouldn't just inject the img
or send the XHR in the first place?
One use-case is script, where's it currently impossible to preload a script without executing it
If we make it a MUST, should it block onload
? If the answer is no, then there is an interesting side effect: effectively, we've implemented lazyload [1]. It's a bit more involved than simply specifying an attribute, but it still seems reasonable:
Hmm? I kinda like it... :)
[1] https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/ResourcePriorities/Overview.html#attr-lazyload
Wouldn't the discovery of the element referencing the resource cause blocking of onload
? Should the fact that it was previously discovered by rel=preload
override that?
If I get what you're suggesting regarding lazyload, I find it confusing that adding a preload
hint/directive would effectively mean that the resource's priority is downgraded. I suspect most authors would expect the opposite.
Not sure I follow, why do you interpret it as "downgraded" priority?
The suggestion from @guypod was to treat preloaded resources as non-blocking unless there is a matching request that is initiated before the load
event is fired -- i.e. preload is simply a directive to the network stack to initiate the download, but it doesn't say anything about whether this resource should block the load
event.
Not sure I follow, why do you interpret it as "downgraded" priority?
Maybe I misunderstood what you meant with "lazyload". Can you elaborate on that?
The suggestion from @guypod was to treat preloaded resources as non-blocking unless there is a matching request that is initiated before the load event is fired -- i.e. preload is simply a directive to the network stack to initiate the download, but it doesn't say anything about whether this resource should block the load event.
That sounds good to me.
Ah, I skipped a few details as well.. I was also thinking about the ability to pass down some priority information to fetch (as recently discussed on what-wg). Let me follow-up on this in a separate thread.. it requires a bit more careful thinking and explanation.
We don't have primitives for preloading (for example) scripts, I was hoping "preload" would provide that by being a MUST, and providing a promise to signal completion.
What's the benefit of "preload" being a hint?