Skip to content
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

FF132 fetchpriority docs updates #36142

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
39 changes: 18 additions & 21 deletions files/en-us/web/api/htmlimageelement/fetchpriority/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,30 @@ page-type: web-api-instance-property
browser-compat: api.HTMLImageElement.fetchPriority
---

{{APIRef}}
{{APIRef("HTML DOM")}}

The **`fetchPriority`** property of the
{{domxref("HTMLImageElement")}} interface represents a hint given to the browser on how
it should prioritize the fetch of the image relative to other images.
hamishwillee marked this conversation as resolved.
Show resolved Hide resolved
The **`fetchPriority`** property of the {{domxref("HTMLImageElement")}} interface represents a hint to the browser indicating how it should prioritize fetching a particular image relative to other images.
It reflects the [`fetchpriority`](/en-US/docs/Web/HTML/Element/img#fetchpriority) attribute of the corresponding {{htmlelement("img")}} element, for the allowed values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "for the allowed values" mean? Are there only a certain subset of attribute values that the property can be used to set? Phrasing seemed odd and made me question this. If it reflects it, pure and simple, remove this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SAme comment on the link and script pages, too.


The property allows a developer to signal that fetching a particular image early in the loading process has more or less impact on user experience than a browser can reasonably infer when assigning an internal priority.
This in turn allows the browser to increase or decrease the priority, and potentially load the image earlier or later than it would otherwise.
The property should be used sparingly, as excessive or incorrect prioritization can degrade performance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all makes sense, but it feels to me like the page needs a short paragraph to describe some actual usage cases of the property (same for the link and script versions). And how does it work alongside other loading performance-related features such as preload and lazy load.

I appreciate this is discussed in great depth in the linked web.dev article, but it feels like this page could benefit with a little bit of usage description.


Note that both the internal priority of any fetch operation, and the impact of `fetchPriority` on the priority, are entirely browser dependent.

## Value

A string representing the priority hint. Possible values are:
A string representing the priority hint.
Possible values are:

- `high`
- : Fetch the image at a high priority relative to other images.
- : Fetch the image at a high priority relative to other images with the same internal prioritization.
- `low`
- : Fetch the image at a low priority relative to other images.
- : Fetch the image at a low priority relative to other images with the same internal prioritization.
- `auto`
- : Default mode, which indicates no preference for the fetch priority.
The browser decides what is best for the user.

The `fetchPriority` property allows you to signal high or low priority image
fetches. This can be useful when applied to {{HTMLElement("img")}} elements
to signal images that are "important" to the user experience early in the
loading process.

The effects of the hint on resource loading is browser-specific so make sure to
test on multiple browser engines.

Use it sparingly for exceptional cases where the browser may not be able to
infer the best way to load the image automatically. Over use can result in
degrading performance.
- : No user preference for the fetch priority.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- : No user preference for the fetch priority.
- : Don't set a user preference for the fetch priority.

Feels like this needed to be changed to make it more of a complete sentence, and more in keeping with the instructive style of the other definitions. Same for the link and script pages too.

This is the default.
It is used if no value is set or if an invalid value is set.

## Examples

Expand All @@ -56,3 +51,5 @@ img.src = "img/logo.png";

- {{domxref("HTMLLinkElement.fetchPriority")}}
hamishwillee marked this conversation as resolved.
Show resolved Hide resolved
- {{domxref("HTMLScriptElement.fetchPriority")}}
- HTTP {{httpheader("Link")}} header
- [Optimize resource loading with the Fetch Priority API](https://web.dev/articles/fetch-priority?hl=en#browser_priority_and_fetchpriority) for information about how this API affects priorities on Chrome.
41 changes: 17 additions & 24 deletions files/en-us/web/api/htmllinkelement/fetchpriority/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,28 @@ browser-compat: api.HTMLLinkElement.fetchPriority

{{APIRef("HTML DOM")}}

The **`fetchPriority`** property of the
{{domxref("HTMLLinkElement")}} interface represents a hint given to the browser
on how it should prioritize the preload of the given resource relative to other
resources of the same
[type](/en-US/docs/Web/HTML/Attributes/rel/preload#what_types_of_content_can_be_preloaded).
The **`fetchPriority`** property of the {{domxref("HTMLLinkElement")}} interface represents a hint to the browser indicating how it should prioritize fetching a particular resource relative to other resources of the same type.
It reflects the [`fetchpriority`](/en-US/docs/Web/HTML/Element/link#fetchpriority) attribute of the corresponding {{htmlelement("link")}} element, for the allowed values.

The property allows a developer to signal that fetching a particular resource early in the loading process has more or less impact on user experience than a browser can reasonably infer when assigning an internal priority, in particular when preloading resources.
This in turn allows the browser to increase or decrease the priority, and potentially load the resource earlier or later than it would otherwise.
The property should be used sparingly, as excessive or incorrect prioritization can degrade performance.

Note that both the internal priority of any fetch operation, and the impact of `fetchPriority` on the priority, are entirely browser dependent.

## Value

A string representing the priority hint. Possible values are:
A string representing the priority hint.
Possible values are:

- `high`
- : Fetch the preload resource at a high priority relative to other resources
of the same type.
- : Fetch the resource at a high priority relative to other resources of the same type and internal prioritization.
- `low`
- : Fetch the preload resource at a low priority relative to other resources of
the same type.
- : Fetch the resource at a low priority relative to other resources of the same type and internal prioritization.
- `auto`
- : Default mode, which indicates no preference for
the fetch priority. The browser decides what is best for the user.

The `fetchPriority` property allows you to signal high or low priority preload
fetches. This can be useful when applied to {{HTMLElement("link")}} elements
to signal preloads that are more or less important to the user experience early
in the loading process.

The effects of the hint on resource loading is browser-specific so make sure to
test on multiple browser engines.

Use it sparingly for exceptional cases where the browser may not be able to
infer the best way to load the resource automatically. Over use can result in
degrading performance.
- : No user preference for the fetch priority.
This is the default.
It is used if no value is set or if an invalid value is set.

## Examples

Expand All @@ -63,3 +54,5 @@ document.head.appendChild(preloadLink);

- {{domxref("HTMLImageElement.fetchPriority")}}
- {{domxref("HTMLScriptElement.fetchPriority")}}
- HTTP {{httpheader("Link")}} header
- [Optimize resource loading with the Fetch Priority API](https://web.dev/articles/fetch-priority?hl=en#browser_priority_and_fetchpriority) for information about how this API affects priorities on Chrome.
30 changes: 12 additions & 18 deletions files/en-us/web/api/htmlscriptelement/fetchpriority/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ browser-compat: api.HTMLScriptElement.fetchPriority

{{APIRef("HTML DOM")}}

The **`fetchPriority`** property of the {{domxref("HTMLScriptElement")}} interface represents a hint given to the browser on how it should prioritize fetching of an external script relative to other external scripts.
The **`fetchPriority`** property of the {{domxref("HTMLScriptElement")}} interface represents a hint to the browser indicating how it should prioritize fetching an external script relative to other external scripts.
It reflects the [`fetchpriority`](/en-US/docs/Web/HTML/Element/script#fetchpriority) attribute of the {{HTMLElement("script")}} element, for the allowed values.

It reflects the `fetchpriority` attribute of the {{HTMLElement("script")}} element.
The property allows a developer to signal that fetching a particular script early in the loading process has more or less impact on user experience than a browser can reasonably infer when assigning an internal priority.
This in turn allows the browser to increase or decrease the priority, and potentially load the script earlier or later than it would otherwise.
The property should be used sparingly, as excessive or incorrect prioritization can degrade performance.

Note that both the internal priority of any fetch operation, and the impact of `fetchPriority` on the priority, are entirely browser dependent.

## Value

Expand All @@ -21,22 +26,9 @@ A string representing the priority hint. Possible values are:
- `low`
- : Fetch the external script at a low priority relative to other external scripts.
- `auto`
- : Default mode, which indicates no preference for the fetch priority.
The browser decides what is best for the user.

If the `fetchpriority` attribute is not specified or is specified with any other value, it is the same as specifying it as `auto`.

The `fetchPriority` property allows you to signal high or low priority external script
fetches. This can be useful when applied to {{HTMLElement("script")}} elements
to signal external scripts that are "important" to the user experience early in the
loading process.

The effects of the hint on resource loading is browser-specific so make sure to
test on multiple browser engines.

Use it sparingly for exceptional cases where the browser may not be able to
infer the best way to load the external script automatically. Over use can result in
degrading performance.
- : No user preference for the fetch priority.
This is the default.
It is used if no value is set or if an invalid value is set.

## Examples

Expand All @@ -61,3 +53,5 @@ console.log(el.fetchPriority); // Output: "high"

- {{domxref("HTMLImageElement.fetchPriority")}}
- {{domxref("HTMLLinkElement.fetchPriority")}}
- HTTP {{httpheader("Link")}} header
- [Optimize resource loading with the Fetch Priority API](https://web.dev/articles/fetch-priority?hl=en#browser_priority_and_fetchpriority) for information about how this API affects priorities on Chrome.
28 changes: 4 additions & 24 deletions files/en-us/web/api/request/request/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,13 @@ new Request(input, options)

### Exceptions

<table class="no-markdown">
<thead>
<tr>
<th scope="col">Type</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>TypeError</code></td>
<td>
Since <a href="/en-US/docs/Mozilla/Firefox/Releases/43">Firefox 43</a>,
<code>Request()</code> will throw a TypeError if the URL has
credentials, such as http://user:[email protected].
</td>
</tr>
</tbody>
</table>
- `TypeError`
- The URL has credentials, such as `http://user:[email protected]` or cannot be parsed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't rendering correctly; you're missing the colon.


## Examples

In our [Fetch Request example](https://github.com/mdn/dom-examples/tree/main/fetch/fetch-request) (see [Fetch Request live](https://mdn.github.io/dom-examples/fetch/fetch-request/)) we
create a new `Request` object using the constructor, then fetch it using a
{{domxref("Window/fetch", "fetch()")}} call. Since we are fetching an image, we run
{{domxref("Response.blob")}} on the response to give it the proper MIME type so it will be
handled properly, then create an Object URL of it and display it in an
{{htmlelement("img")}} element.
In our [Fetch Request example](https://github.com/mdn/dom-examples/tree/main/fetch/fetch-request) (see [Fetch Request live](https://mdn.github.io/dom-examples/fetch/fetch-request/)) we create a new `Request` object using the constructor, then fetch it using a {{domxref("Window/fetch", "fetch()")}} call.
Since we are fetching an image, we run {{domxref("Response.blob")}} on the response to give it the proper MIME type so it will be handled properly, then create an Object URL of it and display it in an {{htmlelement("img")}} element.

```js
const myImage = document.querySelector("img");
Expand Down
3 changes: 2 additions & 1 deletion files/en-us/web/api/requestinit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ You can also construct a `Request` with a `RequestInit`, and pass the `Request`
- `low`
- : A low priority fetch request relative to other requests of the same type.
- `auto`
- : Automatically determine the priority of the fetch request relative to other requests of the same type.
- : No user preference for the fetch priority.
It is used if no value is set or if an invalid value is set.

Defaults to `auto`.

Expand Down
11 changes: 7 additions & 4 deletions files/en-us/web/html/element/img/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attrib

- `fetchpriority`

- : Provides a hint of the relative priority to use when fetching the image. Allowed values:
- : Provides a hint of the relative priority to use when fetching the image.
Allowed values:

- `high`
- : Signals a high-priority fetch relative to other images.
- : Fetch the image at a high priority relative to other images.
- `low`
- : Signals a low-priority fetch relative to other images.
- : Fetch the image at a low priority relative to other images.
- `auto`
- : Default: Signals automatic determination of fetch priority relative to other images.
- : No user preference for the fetch priority.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, feels like this should be written more constructively, to match the style of the other value descriptions. Same for the other HTML attribute descriptions.

This is the default.
It is used if no value or an invalid value is set.

- `height`

Expand Down
11 changes: 7 additions & 4 deletions files/en-us/web/html/element/link/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,17 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attrib

- `fetchpriority`

- : Provides a hint of the relative priority to use when fetching a preloaded resource. Allowed values:
- : Provides a hint of the relative priority to use when fetching a resource of a particular type.
Allowed values:

- `high`
- : Signals a high-priority fetch relative to other resources of the same type.
- : Fetch the resource at a high priority relative to other resources of the same type.
- `low`
- : Signals a low-priority fetch relative to other resources of the same type.
- : Fetch the resource at a low priority relative to other resources of the same type.
- `auto`
- : Default: Signals automatic determination of fetch priority relative to other resources of the same type.
- : No user preference for the fetch priority.
This is the default.
It is used if no value or an invalid value is set.

- `href`
- : This attribute specifies the {{glossary("URL")}} of the linked resource. A URL can be absolute or relative.
Expand Down
11 changes: 7 additions & 4 deletions files/en-us/web/html/element/script/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attrib

- `fetchpriority`

- : Provides a hint of the relative priority to use when fetching an external script. Allowed values:
- : Provides a hint of the relative priority to use when fetching an external script.
Allowed values:

- `high`
- : Signals a high-priority fetch relative to other external scripts.
- : Fetch the external script at a high priority relative to other external scripts.
- `low`
- : Signals a low-priority fetch relative to other external scripts.
- : Fetch the external script at a low priority relative to other external scripts.
- `auto`
- : Default: Signals automatic determination of fetch priority relative to other external scripts.
- : No user preference for the fetch priority.
This is the default.
It is used if no value or an invalid value is set.

- `integrity`
- : This attribute contains inline metadata that a user agent can use to verify that a fetched resource has been delivered without unexpected manipulation. The attribute must not specified when the `src` attribute is not specified. See [Subresource Integrity](/en-US/docs/Web/Security/Subresource_Integrity).
Expand Down
20 changes: 19 additions & 1 deletion files/en-us/web/http/headers/link/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ browser-compat: http.headers.Link

The HTTP **`Link`** [entity header](/en-US/docs/Glossary/Entity_header) field provides a means for serializing one or more links in HTTP headers. This header has the same semantics as the HTML {{HTMLElement("link")}} element. The benefit of using the `Link` header is that the browser can start preconnecting or preloading resources before the HTML itself is fetched and processed.

In practice, most [link types](/en-US/docs/Web/HTML/Attributes/rel) don't have an effect in the HTTP header. For example, the `icon` relation only works in HTML, and `stylesheet` does not work reliably across browsers (only in Firefox). The only relations that work reliably are `preconnect` and `preload`, which can be combined with {{HTTPStatus(103, "103 Early Hints")}}.
In practice, most [link types](/en-US/docs/Web/HTML/Attributes/rel) don't have an effect in the HTTP header. For example, the `icon` relation only works in HTML, and `stylesheet` does not work reliably across browsers (only in Firefox).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In practice, most [link types](/en-US/docs/Web/HTML/Attributes/rel) don't have an effect in the HTTP header. For example, the `icon` relation only works in HTML, and `stylesheet` does not work reliably across browsers (only in Firefox).
In practice, most [link types](/en-US/docs/Web/HTML/Attributes/rel) don't have an effect on the HTTP header. For example, the `icon` relation only works in HTML, and `stylesheet` does not work reliably across browsers (only in Firefox).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or am I wrong? Feels like a weird phrasing when you first read it. But now I'm not so sure.

The only relations that work reliably are [`preconnect`](/en-US/docs/Web/HTML/Attributes/rel/preconnect) and [`preload`](/en-US/docs/Web/HTML/Attributes/rel/preload), which can be combined with {{HTTPStatus(103, "103 Early Hints")}}.

## Syntax

Expand All @@ -26,6 +27,8 @@ The link header contains parameters, which are separated with `;` and are equiva

## Examples

### Enclose URLs in angle brackets

The URI (absolute or relative) must be enclosed between `<` and `>`:

```http example-good
Expand Down Expand Up @@ -56,6 +59,20 @@ You can specify multiple links separated by commas, for example:
Link: <https://one.example.com>; rel="preconnect", <https://two.example.com>; rel="preconnect", <https://three.example.com>; rel="preconnect"
```

### Controlling fetch priority

Even when using [`preload`](/en-US/docs/Web/HTML/Attributes/rel/preload) to fetch a resource as early as possible, different types of content will be fetched earlier or later based on the browser's internal prioritization.
The [`fetchpriority`](/en-US/docs/Web/HTML/Element/link#fetchpriority) attribute can be used to hint to the browser that a particular resource will have a greater or lesser relative impact on user experience than other resources of the same type.

For example, the header below might be used to preload `style.css` at higher priority than other stylesheets:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For example, the header below might be used to preload `style.css` at higher priority than other stylesheets:
For example, the header below might be used to preload `style.css` with a higher priority than other stylesheets:


```http
Link: </style.css>; rel=preload; as=style; fetchpriority="high"
```

Note that both the internal prioritization for fetching resources and the effect of the `fetchpriority` are browser dependent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note that both the internal prioritization for fetching resources and the effect of the `fetchpriority` are browser dependent.
Note that both the internal prioritization for fetching resources and the effect of the `fetchpriority` parameter are browser-dependent.

The `fetchpriority` attribute should be used sparingly, and only in cases where a browser would be unable to infer that a particular resource should be treated with a different priority.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `fetchpriority` attribute should be used sparingly, and only in cases where a browser would be unable to infer that a particular resource should be treated with a different priority.
The `fetchpriority` parameter should be used sparingly, and only in cases where a browser cannot infer that a particular resource should be treated with a different priority.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of the HTTP header, would it be a parameter? "Parameters" is used earlier on the page. Or in HTTP terms, would "directive" be more accurate? In any case, "attribute" probably isn't right.


## Specifications

{{Specifications}}
Expand All @@ -68,3 +85,4 @@ Link: <https://one.example.com>; rel="preconnect", <https://two.example.com>; re

- {{HTTPStatus(103, "103 Early Hints")}}
- {{HTMLElement("link")}}
- [Optimize resource loading with the Fetch Priority API](https://web.dev/articles/fetch-priority?hl=en#browser_priority_and_fetchpriority) for information about how this API affects priorities on Chrome.
1 change: 1 addition & 0 deletions files/en-us/web/http/status/103/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@ Content-Type: text/html
- [Content Security Policy (CSP)](/en-US/docs/Web/HTTP/CSP)
- [`rel="preconnect"`](/en-US/docs/Web/HTML/Attributes/rel/preconnect) ({{htmlelement("link")}} attribute)
- [`rel="preload"`](/en-US/docs/Web/HTML/Attributes/rel/preload) ({{htmlelement("link")}} attribute)
- [`fetchpriority`](/en-US/docs/Web/HTML/Element/link#fetchpriority) ({{htmlelement("link")}} attribute)
- [Early Hints update: How Cloudflare, Google, and Shopify are working together to build a faster Internet for everyone](https://blog.cloudflare.com/early-hints-performance/) from the CloudFlare blog