JavaScript Loading Priorities in Chrome
February 18, 2019
How browsers schedule and execute scripts can impact the performance of web pages. While techniques like <script defer>
, <link rel=preload>
(and others) influence script loading, knowing how browsers interpret them can also be helpful. Thanks to Kouhei Ueno, we now have an up to date summary of script scheduling in Chrome.
Loading priority (network/Blink) |
Execution priority | Where should this be used? | |
<script> in <head>
|
Medium/High | VeryHigh - Blocks parser |
|
<link rel=preload> +<script async> hack
or
|
Medium/High | High - Interrupts parser |
|
<script async>
|
Lowest/Low | High - Interrupts parser |
Be careful when considering <script async> . Today it is often used to indicate non-critical scripts, but is inconsistent in being loaded at low priority and executed at high priority.
|
<script defer>
|
Lowest/Low | VeryLow - Runs after <script> s at end of <body>
|
|
<script> at the end of <body>
|
Medium/High | Low - Waits parser end |
Be careful when using <script> at the end of <body> when you think they are low priority. These scripts are scheduled at Medium/High priority.
|
<script defer> at the end of <body>
|
Lowest/Low - end of the queue |
VeryLow - Runs after <script> s at end of <body>
|
|
<link rel=prefetch> + <script> in a next-page navigation
|
Idle / Lowest | Depends on when and how the script is consumed. | Scripts very likely to provide important functionality to a next-page navigation.
Examples:
|
Note: Loading priorities are not guaranteed to be consistent cross-browser so use this knowledge wisely and measure when unsure. Ideally, aim to delivery a great experience to the widest number of users possible.
If you're a web developer wondering where you can see the "Loading Priority", Chrome DevTools has an optional "Priority" column available in the Network panel. Right-click the column headers and you can switch it on:
This above priorities summary is still true as of February 2019. I would personally love to get a better understanding of loading priorities in other browsers too. Hopefully this overview is useful to someone out there!
Thanks to Kouhei, Dom Faralino, Pat Meenan, Kenji Baheux and Yoav Weiss for their contributions helping better explain Chrome's network stack.