[wp-trac] [WordPress Trac] #59115: Use defer loading strategy for block view scripts
WordPress Trac
noreply at wordpress.org
Tue Aug 15 20:41:51 UTC 2023
#59115: Use defer loading strategy for block view scripts
-------------------------------------+--------------------
Reporter: westonruter | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.4
Component: Editor | Version: trunk
Severity: normal | Keywords:
Focuses: javascript, performance |
-------------------------------------+--------------------
In [https://github.com/WordPress/gutenberg/pull/52536 gutenberg#52536],
the `defer` loading strategy was used for all block view scripts. This
ticket is to backport the Gutenberg change to core. Script loading
strategies were introduced in #12009.
Currently block view scripts are registered without setting the
`$in_footer` argument to `true`. For block themes, this means they will
get printed in the `head` since `the_content` is processed before the
`wp_head` action. For classic themes, however, `the_content` is processed
''after'' `wp_head`, resulting in the scripts being printed at
`wp_footer`. Therefore, given that block view scripts have been printed in
either the `head` or footer already, this means they can safely be made
`defer`. Leaving them in the `head` is advantageous because it means the
browser will discover these scripts earlier and start loading them with
other page resources, but the presence of `defer` means that they will no
longer block page rendering.
This was similarly done for the wp-embed script in #58931.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59115>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list