-
Notifications
You must be signed in to change notification settings - Fork 31
Preload headers on sub resources #92
Comments
This use case comes from Wikipedia (as indicated by the examples and #31). Despite the logo changing once or twice per year on some wikis (e.g. for events or because of minor design adjustments or updated translations for one of the many language editions), we've chosen to go ahead with the preload header regardless using the url that is known to the application at the time the page is saved by the CDN on a cache-miss. This has the caveat that if the logo were to change (temporarily or not), users will needlessly preload the old logo for up to 7 days (our current TTL for most page views) when viewing pages that have not been purged/modified since the logo change. |
@Krinkle all of the above makes sense... and should already work! You can specify preload headers on a subresource and those should be processed. Are you seeing otherwise? /cc @yoavweiss |
@igrigorik I couldn't find anything about it in the spec (also no platform tests, but I guess that's tricky with static files and non-HTML sub resources). Also, there is Link Given that, I would assume the default would be for specs like these to only apply when processing the response for something that can be the subject of a browsing context / HTML Document – assuming of course that the Link rel=stylesheet is not needlessly downloaded in Firefox when the resource in question is a sub resource. When creating a little test of my own, I do indeed find that preload works fine in Chrome for sub resources. See https://gist.github.com/Krinkle/d39cd3d4bd30a10fad5e1ae7f60b4c11 (PHP) Thanks for that! Could you clarify where this is specified in the preload spec? (Or another spec.) That way we can be somewhat confident that when other browsers implement preload, they will do so in the same manner. |
Section 2.1: https://w3c.github.io/preload/#processing
The above doesn't distinguish between navigation or subresource responses, and intentionally so. Personally, I don't think we need to explicitly spell this out? /cc @yoavweiss |
This should Just Work™, and I agree with @igrigorik that we don't need to spell it out in normative text. An example as well as a WPT might be in order though. |
Test is at web-platform-tests/wpt#6933 |
Preload is useful as it allows one to help the browser discover a resource before it would/could naturally discover it. Especially with regards to indirection (e.g. the resource is not already specified directly somewhere in the HTML document, or is sufficiently far down in the source that it makes sense to specify it higher up or in a header as well).
However, sometimes this indirection is inevitable or even by design. Three use cases laid out below:
Background image. Wikipedia's sidebar is toward the bottom of the HTML payload - after the main content. In addition, the main logo is actually specified by a CSS background-image, not an IMG element. As such, browser don't fetch the logo until the CSS is downloaded/parsed and the entire HTML payload is download, parsed and has its styles applied.
Immutable scripts from a "startup" module. ResourceLoader's design document explains how all JS modules are served from immutable urls. That is to say, the module urls are versioned using a hash of their content. However, to ensure a consistent user experience from one page to another, and to allow quick deployments, the urls are not embedded in the (CDN-cached) HTML. Instead, we may use of an (async) "startup" script - which is the only mutable script ("not versioned"). As such the urls to the main script payloads is in this script response and not fetched until the browser has downloaded, parsed and executed this first JavaScript resource.
Third-party sub resources. This use case doesn't apply to me personally, but I've seen it elsewhere. You include a third-party script (e.g. Google JS libraries, or stylesheet (e.g. something like jQuery UI or Bootstrap CSS). This third-party resource has sub resources (images, or other scripts) that are not discovered until run time.
These cases have three things in common:
In these cases I think a significant improvement can be made without violating the requirements. Namely if we could specify preload of resources on sub resources.
The text was updated successfully, but these errors were encountered: