HTMLScriptElement: fetchPriority property
Baseline2024Newly available
Since October 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
ThefetchPriority
property of theHTMLScriptElement
interface represents a hint to the browser indicating how it should prioritize fetching an external script relative to other external scripts.It reflects thefetchpriority
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 ofasync
scripts without having to usepreloading.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 offetchPriority
on the priority, are entirely browser dependent.
Value
A string representing the priority hint. Possible values are:
Examples
<script type="module" src="main.js" fetchpriority="high"></script>
const el = document.getElementById("el");console.log(el.fetchPriority); // Output: "high"
Specifications
Specification |
---|
HTML # dom-script-fetchpriority |
Browser compatibility
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.