Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Extended the use cases and added usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavweiss committed Sep 18, 2017
1 parent a003f62 commit 16ec026
Showing 1 changed file with 86 additions and 6 deletions.
92 changes: 86 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
# Resource Priorities
# Priority Hints

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 18, 2017

Author Contributor

@addyosmani @jakearchibald @KenjiBaheux - as I'm failing to sleep on the flight over to blinkon, I've added many words. Please review to make sure they make sense.
Kenji - I think I incorporated all the use cases from your doc. Let me know if anything is still missing.

This comment has been minimized.

Copy link
@addyosmani

addyosmani Sep 19, 2017

Collaborator

I like the Priority Hints rewording here. Will take a look at the text additions. Assume this was done as a merge commit vs. PR as we wanted the text in before BlinkOn :)

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 19, 2017

Author Contributor

Yeah :)

Let's still iterate over the text nevertheless.


The browser's resource loading process is a complex process in which it
discovers resources and downloads them according to its heuristic
priority for that resource. Often browsers also delay the sending of
certain requests in order to avoid bandwidth contention of these
resources with more critical ones, again based on heuristic "importance".

This comment has been minimized.

Copy link
@addyosmani

addyosmani Sep 19, 2017

Collaborator

Worth adding ~browsers offer very limited control over modifying the priority of resource requests (preload), meaning more often than not the browsers own heuristics are what we rely on?

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 19, 2017

Author Contributor

Sounds good, but maybe in the section below?

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 19, 2017

Author Contributor

Regarding this section, might be better to rewrite as "The browser's resource loading process is a complex one. Browsers discover needed resources and download them according to their heuristic priority. Browsers may also use this heuristic resource priority to delay sending certain requests in order to avoid bandwidth contention of these resources with more critical ones."


Currently there is no way for web developers to tell the browser
about the importance of the resources that they are loading. Browsers

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 19, 2017

Author Contributor

"Currently web developers have very little control over the heuristic importance of loaded resources, other than speeding up their discovery using <link rel=preload>"

make many assumptions on the importance of resources based on the
resource's type (AKA its request destination), and based on its location
in the containing document.
The goal of the API and markup solutions in this specification is to
provide developers with that control.

This document will detail use cases and an API/markup sketch that will
provide developers with the required controls to indicate the browser
with a resource's relative importance, and enable the browser to act on

This comment has been minimized.

Copy link
@addyosmani

addyosmani Sep 19, 2017

Collaborator

That will provide developers with the control to indicate a resource's relative importance to the browser. I think as this currently reads it sounds like they're indicating "the browser" rather than the resource priority "to the browser".

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 19, 2017

Author Contributor

you're right, your wording's better

those indications to modify the time it sends out the request and its
HTTP/2 dependency/weight so that important resources are fetched and used
earlier, in order to improve the user's experience.

## Use Cases

This section outlines the different use-cases this effort sets to
address. It is worth noting that priority in these examples should not
limit itself to network priority (i.e. request time and HTTP/2
dependencies and weights), but also to processing priority, as the
browser can use the same signals in order to avoid processing of low
priority resource in favor of higher priority ones.

### Communicate resource importance to the browser
The browser assigns priorities and certain dependencies to downloaded
resources and uses them to determine:
Expand All @@ -27,7 +45,10 @@ A few examples:
* Markup images are typically loaded with low/medium priority, but may
be critical to the user experience, so for certain images, the
developer may want to indicate that their importance only falls short of
the page's render blocking resources.
the page's render blocking resources. A prominent example of that is
the page's image in an image sharing site, where the image is the
main content users are looking for. Another example is a single-page-app
where route fetches must run at highest priority.
* Async Javascript files may be loaded by default with low priority, but
some of them may be of high priority and should be loaded at the same
time as the page's render blocking resources. Developers currently use
Expand All @@ -49,6 +70,10 @@ to the server first. That can result in loading regressions as the
server may start sending those non-critical resources before other, more
critical ones, which may fill up the TCP socket sending queues.
While better transport protocols (e.g. QUIC) may address that at a lower layer for the single origin case, developers should be able to signal to the browser that a certain resource is not critical, and therefore should be queued until such resources are discovered.
Such marking as "non-critical" should be orthogonal to the signaling of
the resource's "importance" (e.g. this could be applied to high priority
resources that shouldn't contend with rendering-critical resources as
well as low priority ones).

### Avoid bandwidth contention in multiple origin scenarios
When loading resources from multiple origins, setting HTTP/2
Expand All @@ -67,13 +92,21 @@ e.g. `Link:`)
### Provide priority signals for dynamically loaded resources
Developers need a way to provide the above signals for resources that
are fetched through Javascript, e.g. using the `fetch()` API.
That would enable them both to upgrade and downgrade those resource's
"importance".

### Provide the ability to re-prioritize a resource in-flight
"Resource priority" is not always the right way of looking at it. For
* "Resource priority" is not always the right way of looking at it. For
resources that are parsed on-the-fly (most notably HTML and progressive images),
their first buffer is often more important than their last. Developers
can use the ability to reprioritize resources to reflect that when
downloading such resources.
* There are also cases where the priority of a resource changes due to
user action or condition changes. One example is the loading of
images, where in-viewport images (or soon-to-be in-viewport images) are
of higher priority than images that are further away from the viewport
and therefore less likely to be seen by the user.


### Downgrade priority of an iframe and its subresources
When developers load a third party iframe, they may wish to make sure
Expand All @@ -85,6 +118,53 @@ accordingly.
When such a signal is applied to an iframe, it should be equally applied
to all the subresources that the iframe loads.

### Adoption path
Markup based signal should be added in a way such that non-supporting
browsers will simply ignore them and load all resources, potentially not
in the intended priority and dependency. Script based signaling APIs
should be created in a way that non-supporting browsers simply ignore
the signals.

## Out of scope
* Signal that certain images should not block the load event
* Signals relating the script execution order, script execution
grouping, execution dependency, etc

## Solution
We propose to address the above use-cases using the following concepts:
* We will define a new set of standard `fetch-groups` that will map to current
browser priorities: `critical`, `fonts`, `functional`, `visual`, `late`
* Names TBB (to be bikeshedded)

This comment has been minimized.

Copy link
@jakearchibald

jakearchibald Sep 20, 2017

Are the names going to reflect the type of thing being fetched, the priority, or some kind of behaviour.

  • fonts looks like it's describing the type of thing, and suggests there should be other groups like images, scripts etc.
  • critical looks like it's describing the priority.
  • visual looks like it's describing some kind of dynamic priority based on behaviour.

I know we're not at the stage of naming these, but it might be worth thinking about the type of names. I think I prefer naming by type of thing, but I haven't thought too hard about it.

Will I be able to create my own fetch group?

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 20, 2017

Author Contributor

IMO the names should reflect "when is the thing usually loaded" and not "what the thing is".
So, you're right and fonts is not a good choice.
In visual I was going for "things that are important for a visually complete initial viewport" (e.g. in-viewport images), but did not mean for that to represent dynamic priority.

Would textcritical be a good replacement for fonts? What's a good alternative to visual in your view?

This comment has been minimized.

Copy link
@yoavweiss

yoavweiss Sep 20, 2017

Author Contributor

Regarding being able to create custom fetch groups, we discussed it today at BlinkOn. As it will add a lot of complexity and as it is not critical for most use-cases, we're thinking of postponing that to v2.

* Developers would be able to assign resources into those groups or
define resources as more or less important than said groups.
* Developers would be able to define custom fetch groups, and assign
resources to them, or define them as more or less important than said
groups
* This is necessary in order to be able to define two "levels" of
resource importance between existing groups.
* TODO: Is this use case worth the extra complexity? Any examples
where this is required?

## Usage Examples

TBD
* `<img src=foo group=visual>` - would signify that an img is to be loaded
with relatively high priority as it's impacting the initial visual.
* `<img src=foo before=visual>` - would signify that an img is to be loaded
with higher priority than other visually impacting resources. (e.g.
since it's a hero image, more important than other in-viewport images)
* `<link rel=preload href=foo as=image group=visual>` - signifies that
the image should be preloaded as impacting the initial visual, but not
load before critical resources were discovered, as it will likely
contend on bandwidth with them.
* `<link rel=preload href=foo as=image group=critical>` - A page which
has no critical resources (e.g. they are all inlined) can tell the
browser to kick off an image preload as soon as it encounters it.
* That's already the default behavior of browsers, but developers
would be able to explicitly state that preference.
* `<link rel=stylesheet href=foo group=late>` - can be used to indicate
non-blocking style which isn't impacting the initial visual
experience.
* `<iframe src=foo group=late>` - would downgrade the importance of the
iframe and all its subresources.
* TBD - what does the fetch API parameter look like?
* TBD - how does explicit reprioritization look like?

0 comments on commit 16ec026

Please sign in to comment.