[wp-trac] [WordPress Trac] #59316: Incorporate script loading strategies in bundled themes
WordPress Trac
noreply at wordpress.org
Thu Sep 7 22:31:01 UTC 2023
#59316: Incorporate script loading strategies in bundled themes
-------------------------------------+--------------------
Reporter: westonruter | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.4
Component: Bundled Theme | Version: 6.3
Severity: normal | Keywords:
Focuses: javascript, performance |
-------------------------------------+--------------------
As of #12009 the script loader now has the ability for scripts to be
printed with `async` or `defer`. This is being used on the frontend now
for block view scripts (#59115), the `comment-reply` script (#58870), and
the `wp-embed` script (#58931). Nevertheless, these new script loading
strategies are not currently being used in the bundled themes. There are
opportunities to improve performance by doing so.
It turns out that Twenty Twenty actually has a custom implementation of
script loading strategy injection which can now be deprecated in favor of
what is in core.
In general, any script that involves anything to do with the header
(initial viewport) should get moved to the `head` (if it was registered as
being `$in_footer`) and applied the `defer` loading strategy. This will
ensure that the script will start loading earlier so that as soon as the
DOM has loaded the logic can run and minimize the amount of time that the
initial viewport is in an uninitialized state. Note that `defer` is
preferable to `async` for scripts in the `head` because if the script is
cached an `async` script can actually block rendering whereas a `defer`
script never will.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59316>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list