731 views
# `fetchpriority` support in Mozilla ## Support for HTTP/2 [[1]](#Notes) - ◈: `network.fetchpriority` disabled - ◉: default or `fetchpriority=auto` - ⬆: `fetchpriority=high` - ⬇: `fetchpriority=low` |[`nsISupportsPriority`](https://searchfox.org/mozilla-central/rev/57516f1ab5660f9abf459300bc625279eb323213/xpcom/threads/nsISupportsPriority.idl#19)|Highest|High|Normal|Low|Lowest| |-|-|-|-|-|-| |[`non-deferred-style`](https://searchfox.org/mozilla-central/search?q=non-deferred-style&path=StaticPrefList.yaml): `<link rel=stylesheet>` and equivalent HTTP Link header. |⬆||◈◉⬇||| |[`deferred-style`](https://searchfox.org/mozilla-central/search?q=deferred-style&path=StaticPrefList.yaml): `<link rel=stylesheet>` with [`media` mismatch or `alternate`](https://searchfox.org/mozilla-central/rev/57516f1ab5660f9abf459300bc625279eb323213/layout/style/SheetLoadData.h#240) ; and equivalent HTTP Link header.|||◈◉⬆|⬇|| |[`link-preload-style`](https://searchfox.org/mozilla-central/search?q=link-preload-style&path=StaticPrefList.yaml): `<link rel=preload as=style>` and equivalent HTTP Link Header [[9]](#Notes)|◈◉⬆|⬇||| |[`script-in-head`](https://searchfox.org/mozilla-central/search?q=module-script&path=StaticPrefList.yaml): `<script>` in head ||⬆|◈◉|⬇| |[`module-script`](https://searchfox.org/mozilla-central/search?q=module-script&path=StaticPrefList.yaml): `<script type=module>` ||⬆|◈◉|⬇|| |[`async-or-defer-script`](https://searchfox.org/mozilla-central/search?q=async-or-defer-script&path=StaticPrefList.yaml): `<script>` (`async`, `defer` or dynamically inserted) ||⬆|◈◉|⬇|| |[`other-script`](https://searchfox.org/mozilla-central/search?q=other-script&path=StaticPrefList.yaml): `<script>` in body [[2]](#Notes) ||⬆|◈◉|⬇|| | SVG `<script>` [[3]](#Notes) |||◈◉||| |[`link-preload-script`](https://searchfox.org/mozilla-central/search?q=link-preload-script&path=StaticPrefList.yaml): `<link rel=preload as=script>`, `<link rel=modulepreload>` and equivalent HTTP Link headers [[9]](#Notes)|◈◉⬆|||⬇|| |[`images`](https://searchfox.org/mozilla-central/search?q=network\.fetchpriority\.adjustments\.images&path=StaticPrefList.yaml): `<img>`, `<link rel=preload as=image>` and equivalent HTTP Link header. ||⬆||◈◉<br/>[[7]](#Notes) [[9]](#Notes)|⬇| | SVG `<image>` ||||◈◉<br/>[[5]](#Notes) [[7]](#Notes)|| | `shape-outside: url(...);` ||||◈◉|| | `@font-face` ||◈◉|||| |[`link-preload-font`](https://searchfox.org/mozilla-central/search?q=link-preload-font&path=StaticPrefList.yaml):`<link rel=preload as=font>` and equivalent HTTP Link header [[9]](#Notes)||◈◉⬆||⬇|| |[`link-preload-fetch`](https://searchfox.org/mozilla-central/search?q=link-preload-fetch&path=StaticPrefList.yaml): `<link rel=preload as=fetch>` and equivalent HTTP Link header [[9]](#Notes)||⬆|◈◉|⬇|| |`<link rel=prefetch>` and equivalent HTTP Link header [[9]](#Notes)|||||◈◉⬆⬇| | [`global-fetch-api`](https://searchfox.org/mozilla-central/search?q=network\.fetchpriority\.adjustments\.global-fetch-api&path=StaticPrefList.yaml):`fetch(input, init)` [[8]](#Notes) [[9]](#Notes)||⬇|◈◉|⬆|| ## Comparison with Google's web.dev article Google provides a [similar table](https://web.dev/articles/fetch-priority?hl=en#browser_priority_and_fetchpriority) which likely corresponds to Chromium's behavior, with the following labels: - CSS: `rel=stylesheet` or `preload`/`fetch` with `style` destination [[9]](#Notes). - Script: `<script>` or `preload`/`fetch` with `script` destination [[9]](#Notes). - Early/Late: This is used for CSS and Script and is defined as being requested before/after any non-preloaded images have been requested. - Font: `@font-face` or `preload`/`fetch` with `font` destination [[9]](#Notes). - Import: `@impor`, `import "..."``with `{ type: "css` }` ; or `importScripts`? - Image: `<img>` or `preload`/`fetch` with `image` destination [[9]](#Notes). The table also contains more specific cases with different priority: "in viewport - after layout" and "first 5 images > 10,000px2)". - Media (video/audio): `<video/audio>` or `preload`/`fetch` with `audio/video` destination [[9]](#Notes). The `fetchpriority` attribute has no effect on the `<video/audio>` elements, though. - SVG document: This is likely just the same as Image, but linking to an SVG document. The spec does not say anything about using MIME type to adjust priority or about an svg-specific destination, so it's unclear` - XHR(sync): `XMLHttpRequest.open(method, url, async=false)`. - XHR(async): `XMLHttpRequest.open(method, url, async=true)`. - Prefetch: `<link rel=prefetch` or `fetch` with a `prefetch` initiator. - XSL: `preload`/`fetch` with `xslt` destination or `xlst` initiator. ## Notes 1. [`fetchpriority` HTTP/3 is not supported yet](https://bugzilla.mozilla.org/show_bug.cgi?id=1864392), [Extensible Prioritization Scheme for HTTP/2 is not implemented yet](https://bugzilla.mozilla.org/show_bug.cgi?id=1865040). The spec mentions "equivalent information used to prioritize dispatch and processing of HTTP/1 fetches" but it's not clear whether we want to do that and what should be done exactly. 2. Chromium defaults to high for what they call "early" `<script>` in body but [we don't do that](https://bugzilla.mozilla.org/show_bug.cgi?id=1872654). 3. [svg:script@fetchpriority not in the spec](https://bugzilla.mozilla.org/show_bug.cgi?id=1847712). Non-dynamic SVG `<script>` in head don't seem possible with the HTML parser and [speculative parsing ignores async/defer attributes](https://bugzilla.mozilla.org/show_bug.cgi?id=1880046). 4. ~~[img@fetchpriority not implemented yet](https://bugzilla.mozilla.org/show_bug.cgi?id=1839313).~~ 5. [image@fetchpriority not in the spec](https://bugzilla.mozilla.org/show_bug.cgi?id=1865837). 6. ~~[`<link rel=preload as=image>` and equivalent `header` not implemented yet](https://bugzilla.mozilla.org/show_bug.cgi?id=1872657).~~ 7. For images, current, internal priority is initially set to Low but can be adjusted later to a value outside the predefined one in `nsISupportsPriority`: - [priority is decreased a bit for images with the LOAD_BACKGROUND flag](https://searchfox.org/mozilla-central/rev/a8cc31504a2379bcf8ba395d2da7bb632b5521d6/image/imgLoader.cpp#957) (including preload images). - [priority is boosted for some categories of images](https://searchfox.org/mozilla-central/rev/a8cc31504a2379bcf8ba395d2da7bb632b5521d6/image/imgRequest.cpp#526). 8. `init`'s priority overrides `input`'s priority. 9. Chromium makes sure `preload` using `as` or `fetch` using a specific [destination](https://fetch.spec.whatwg.org/#concept-request-destination) uses the priority of the destination they are requesting but [we don't do that yet](https://bugzilla.mozilla.org/show_bug.cgi?id=1881040). ## References ### Fetch spec * [Fetching](https://fetch.spec.whatwg.org/#fetching), step 15: > If request’s [internal priority](https://fetch.spec.whatwg.org/#request-internal-priority) is null, then use request’s priority, initiator, destination, and render-blocking in an implementation-defined manner to set request’s internal priority to an implementation-defined object. - [priority](https://fetch.spec.whatwg.org/#request-priority): > A request has an associated priority, which is "high", "low", or "auto". Unless stated otherwise it is "auto". - [initiator](https://fetch.spec.whatwg.org/#concept-request-initiator): > A request has an associated initiator, which is the empty string, "download", "imageset", "manifest", "prefetch", "prerender", or "xslt". Unless stated otherwise it is the empty string. - [destination](https://fetch.spec.whatwg.org/#concept-request-destination): > A request has an associated destination, which is the empty string, "audio", "audioworklet", "document", "embed", "font", "frame", "iframe", "image", "json", "manifest", "object", "paintworklet", "report", "script", "serviceworker", "sharedworker", "style", "track", "video", "webidentity", "worker", or "xslt". Unless stated otherwise it is the empty string. - [render-blocking](https://fetch.spec.whatwg.org/#request-render-blocking) > A request has an associated boolean render-blocking. Unless stated otherwise, it is false. > Note: This flag is for exclusive use by HTML’s render-blocking mechanism. > Note: The implementation-defined object could encompass stream weight and dependency for HTTP/2, priorities used in Extensible Prioritization Scheme for HTTP for transports where it applies (including HTTP/3), and equivalent information used to prioritize dispatch and processing of HTTP/1 fetches. [RFC9218] * [new `Request(input, init)`](https://fetch.spec.whatwg.org/#dom-request): - Step 5 and 6 set request to a new request (if input is a string) or to input's request (if it is a Request object). - Step 12 set request to a new request, copying the internal priority. - Step 27 takes `init["priority"]` into account to update request’s priorities in an implementation-defined manner. ### HTML5 spec - [Fetch priority attributes](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes) - [script@fetchpriority](https://html.spec.whatwg.org/multipage/scripting.html#attr-script-fetchpriority) - [link@fetchpriorty](https://html.spec.whatwg.org/multipage/semantics.html#attr-link-fetchpriority) - [img@fetchpriority](https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element:fetch-priority-attribute) - [Link processing options](https://html.spec.whatwg.org/multipage/semantics.html#link-processing-options) - [Apply link options from parsed header attributes](https://html.spec.whatwg.org/multipage/semantics.html#apply-link-options-from-parsed-header-attributes) - [Process early hint headers](https://html.spec.whatwg.org/multipage/semantics.html#process-early-hint-headers) ### HTTP spec - HTTP/1.1: [RFC2616](www.rfc-editor.org/rfc/rfc2616) - HTTP/2: [RFC7540](www.rfc-editor.org/rfc/rfc7540) - Extensible Prioritization Scheme for HTTP: [RFC9218](https://www.rfc-editor.org/rfc/rfc9218.html) - HTTP/3: [RFC9114](https://httpwg.org/specs/rfc9114.html) ### Misc * [Bugzilla meta bug](https://bugzilla.mozilla.org/showdependencytree.cgi?id=1797715) * [Speculative parsing](https://developer.mozilla.org/en-US/docs/Glossary/speculative_parsing) * [web.dev article from Google](https://web.dev/articles/fetch-priority?hl=en) * [network.fetchpriority.enabled flag](https://searchfox.org/mozilla-central/rev/57516f1ab5660f9abf459300bc625279eb323213/modules/libpref/init/StaticPrefList.yaml#11769) * [WPT support for adding HTTP header in response](https://web-platform-tests.org/writing-tests/server-pipes.html#headers)