[wp-trac] [WordPress Trac] #59316: Incorporate script loading strategies in bundled themes
WordPress Trac
noreply at wordpress.org
Wed Sep 13 17:13:32 UTC 2023
#59316: Incorporate script loading strategies in bundled themes
---------------------------+--------------------------------------
Reporter: westonruter | Owner: westonruter
Type: enhancement | Status: reopened
Priority: normal | Milestone: 6.4
Component: Bundled Theme | Version: 6.3
Severity: normal | Resolution:
Keywords: has-patch | Focuses: javascript, performance
---------------------------+--------------------------------------
Comment (by westonruter):
Replying to [comment:6 peterwilsoncc]:
> Generally WP tries to keep bundled themes compatible with the WordPress
version in which they were introduced. As an example of this, 2011 checks
the [https://github.com/WordPress/wordpress-
develop/blob/c696a2f773d9e5d61ea39e46f5d95f4442c63dfa/src/wp-
content/themes/twentyeleven/inc/block-patterns.php block pattern functions
exist] prior to calling them.
>
> I think these changes and those in #59302 will need to be modified to
account for the older function signature.
The function signature change from `bool` to `array|bool` was actually
anticipating backwards-compatibility. For example, if someone does:
{{{#!php
<?php
wp_enqueue_script(
'foo',
'https://example.org/foo.js',
array(),
false,
array(
'strategy' => 'defer',
'in_footer' => false,
)
);
}}}
The array being passed in as `$in_footer` will result in WP<6.3 as the
value being truthy and thus effectively being treated the same as `true`
in both [https://github.com/WordPress/wordpress-
develop/blob/52226e0308918474a0ac4ab8017e091ed3ae692a/src/wp-
includes/functions.wp-scripts.php#L346-L351 wp_enqueue_script()] and
[https://github.com/WordPress/wordpress-
develop/blob/52226e0308918474a0ac4ab8017e091ed3ae692a/src/wp-
includes/functions.wp-scripts.php#L173-L179 wp_register_script()]. The
`defer` loading strategy is essentially the same behavior as
`$in_footer=true` because execution happens at the end of the document
loading in both cases. The enhancement for using `defer` here is that the
script can start loading earlier, but if it loads later once encountered
in the footer there isn't any functional difference.
The only back-compat case where this doesn't work as expected is if the
script has to be executed in the `head`, such as if they passed `array(
'in_footer' => false )` without any strategy. However, this wasn't the
case for any of the core themes: they were all already being printed in
the footer (or in the case of Twenty Twenty, using a loading strategy;
also see [https://github.com/WordPress/wordpress-
develop/pull/5170/files#r1324822884 exception] in Twenty Eleven).
So I don't see this as being a case where there is a backwards-
compatibility break. Do you? I know @flixos90 has some additional
thoughts.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59316#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list