HTMLScriptElement: fetchPriority property
The fetchPriority
property of the 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
attribute of the <script>
element.
The property allows a developer to signal that fetching a particular script early or late 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.
The fetch priority allows you to decrease the priority of late-body scripts, or to increase the priority of async
scripts without having to use preloading.
When early loading of a script is important, the priority can be used to complement preloading, boosting the priority ahead of less-impactful resources that have a higher default priority.
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:
high
-
Fetch the external script at a high priority relative to other external scripts.
low
-
Fetch the external script at a low priority relative to other external scripts.
auto
-
Don't set a 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
<script id="el" type="module" src="main.js" fetchpriority="high"></script>
const el = document.getElementById("el");
console.log(el.fetchPriority); // Output: "high"
Specifications
Specification |
---|
HTML Standard # dom-script-fetchpriority |
Browser compatibility
BCD tables only load in the browser
See also
HTMLImageElement.fetchPriority
HTMLLinkElement.fetchPriority
- HTTP
Link
header - Optimize resource loading with the Fetch Priority API for information about how this API affects priorities on Chrome.