|
| 1 | +## Usage Examples |
| 2 | + |
| 3 | +* `<img src=foo group=visual>` - An image is to be loaded with relatively high |
| 4 | + priority as it's impacting the initial visual. |
| 5 | +* `<img src=foo before=visual>` - An image is to be loaded with higher priority |
| 6 | + than other visually impacting resources. (e.g. since it's a hero image, more |
| 7 | + important than other in-viewport images) |
| 8 | +* `<link rel=preload href=foo as=image group=visual>` - An image should be |
| 9 | + preloaded as impacting the initial visual, but not load before critical |
| 10 | + resources were discovered, as it will likely contend on bandwidth with them. |
| 11 | +* `<link rel=preload href=foo as=image group=critical>` - An image should be |
| 12 | + preloaded as a critical resource (e.g. potentially because the page has no |
| 13 | + other critical resources as they are all inlined) |
| 14 | + * That's already the default behavior of browsers in current |
| 15 | + implementations, but developers would be able to explicitly state that |
| 16 | + preference. |
| 17 | +* `<link rel=stylesheet href=foo group=late>` - can be used to indicate |
| 18 | + non-blocking style which isn't impacting the initial visual experience. |
| 19 | +* `<iframe src=foo group=late>` - would downgrade the importance of the iframe |
| 20 | + and all its subresources. |
| 21 | +* TBD - what does the fetch API parameter look like? |
| 22 | +* TBD - how does explicit reprioritization look like? |
| 23 | + |
| 24 | + |
| 25 | +## Use Cases |
| 26 | + |
| 27 | +This section outlines the different use-cases this effort sets to |
| 28 | +address. It is worth noting that priority in these examples should not |
| 29 | +limit itself to network priority (i.e. request time and HTTP/2 |
| 30 | +dependencies and weights), but also to processing priority, as the |
| 31 | +browser can use the same signals in order to avoid processing of low |
| 32 | +priority resource in favor of higher priority ones. |
| 33 | + |
| 34 | +### Communicate resource importance to the browser |
| 35 | +The browser assigns priorities and certain dependencies to downloaded |
| 36 | +resources and uses them to determine: |
| 37 | +* When the resource's request is sent to the server. |
| 38 | +* What HTTP/2 dependencies and weights are assigned to the resource's |
| 39 | + request. |
| 40 | + |
| 41 | +The browser uses various heuristics in order to do the above, which are |
| 42 | +based on the type of resource, its location in the document and more. |
| 43 | + |
| 44 | +Occasionally, web developers are in a better position to know which |
| 45 | +resources are more impactful than others on their users' loading experience, |
| 46 | +and need a way to communicate that to the browser. |
| 47 | + |
| 48 | +A few examples: |
| 49 | +* Markup images are typically loaded with low/medium priority, but may |
| 50 | + be critical to the user experience, so for certain images, the |
| 51 | +developer may want to indicate that their importance only falls short of |
| 52 | +the page's render blocking resources. A prominent example of that is |
| 53 | +the page's image in an image sharing site, where the image is the |
| 54 | +main content users are looking for. Another example is a single-page-app |
| 55 | +where route fetches must run at highest priority. |
| 56 | +* Async Javascript files may be loaded by default with low priority, but |
| 57 | + some of them may be of high priority and should be loaded at the same |
| 58 | +time as the page's render blocking resources. Developers currently use |
| 59 | +[hacks](https://twitter.com/cramforce/status/900445266750263296) to |
| 60 | +address that use-case. |
| 61 | +* Blocking scripts are often of high/medium priority (depends on their |
| 62 | + location in the page and other heuristics), yet sometimes developers |
| 63 | +want to avoid them interfering with e.g. loading of viewport images. |
| 64 | +* Third-party resources (e.g scripts from ads) are often loaded with |
| 65 | +medium/high priority, but developers may wish to load them all at low |
| 66 | +priority. Similarly, developers may wish to load all first-party |
| 67 | +resources that are critical with a high priority. |
| 68 | +* When developers download a group of resources as a result of user interaction, those |
| 69 | +resources download priorities don't take into account the eventual usage and importance |
| 70 | +of those resources. Developers may wish to load these resources with priorities and |
| 71 | +dependencies which better represent their usage and the user's needs |
| 72 | +* Single-page applications can kick off multiple API requests to |
| 73 | +bootstrap the user experience. Developers may wish to load critical |
| 74 | +API requests at a high priority and have better control over scheduling |
| 75 | +priority for the rest. |
| 76 | + |
| 77 | +### Signal a resource as non-critical |
| 78 | +Using `<link rel=preload>` in order to get the browser to early |
| 79 | +discover certain resources, especially in its header form, means that the |
| 80 | +browser may discover these resources before other, more critical resources and |
| 81 | +send their request to the server first. That can result in loading regressions |
| 82 | +as the server may start sending those non-critical resources before other, more |
| 83 | +critical ones, which may fill up the TCP socket sending queues. |
| 84 | +While better transport protocols (e.g. QUIC) may address that at a lower layer |
| 85 | +for the single origin case, developers should be able to signal to the browser |
| 86 | +that a certain resource is not critical, and therefore should be queued until |
| 87 | +such resources are discovered. |
| 88 | +Such marking as "non-critical" should be orthogonal to the signaling of |
| 89 | +the resource's "importance" (e.g. this could be applied to high priority |
| 90 | +resources that shouldn't contend with rendering-critical resources as |
| 91 | +well as low priority ones). |
| 92 | + |
| 93 | +### Avoid bandwidth contention in multiple origin scenarios |
| 94 | +When loading resources from multiple origins, setting HTTP/2 |
| 95 | +dependencies and weights do very little to avoid bandwidth contention |
| 96 | +between the origins, as each origin tries to send down its most critical |
| 97 | +resource without knowing of more critical resources in other origins. |
| 98 | +Signaling resource importance to the browser can enable it to defer |
| 99 | +sending of non-critical third party requests while critical resources |
| 100 | +are still being downloaded. |
| 101 | + |
| 102 | +### Provide priority signals for markup-based resources |
| 103 | +Developers need a way to provide the above signals for resources that |
| 104 | +are loaded through markup (or through markup-equivalent HTTP headers, |
| 105 | +e.g. `Link:`) |
| 106 | + |
| 107 | +### Provide priority signals for dynamically loaded resources |
| 108 | +Developers need a way to provide the above signals for resources that |
| 109 | +are fetched through Javascript, e.g. using the `fetch()` API. |
| 110 | +That would enable them both to upgrade and downgrade those resource's |
| 111 | +"importance". |
| 112 | + |
| 113 | +### Provide the ability to re-prioritize a resource in-flight |
| 114 | +* "Resource priority" is not always the right way of looking at it. For |
| 115 | +resources that are parsed on-the-fly (most notably HTML and progressive images), |
| 116 | +their first buffer is often more important than their last. Developers |
| 117 | +can use the ability to reprioritize resources to reflect that when |
| 118 | +downloading such resources. |
| 119 | +* There are also cases where the priority of a resource changes due to |
| 120 | + user action or condition changes. One example is the loading of |
| 121 | +images, where in-viewport images (or soon-to-be in-viewport images) are |
| 122 | +of higher priority than images that are further away from the viewport |
| 123 | +and therefore less likely to be seen by the user. |
| 124 | + |
| 125 | +### Downgrade priority of an iframe and its subresources |
| 126 | +When developers load a third party iframe, they may wish to make sure |
| 127 | +that it does not contend on bandwidth and/or CPU with the more important |
| 128 | +first party content of the page. Alternatively, they may wish to |
| 129 | +signal the browser that a certain third party iframe is as important as |
| 130 | +the main page content and should be given CPU and bandwidth resources |
| 131 | +accordingly. |
| 132 | + |
| 133 | +When such a signal is applied to an iframe, it should be equally applied |
| 134 | +to all the subresources that the iframe loads. |
0 commit comments