[wp-trac] [WordPress Trac] #59316: Incorporate script loading strategies in bundled themes

WordPress Trac noreply at wordpress.org
Wed Sep 13 00:25:23 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
---------------------------+--------------------------------------
Changes (by peterwilsoncc):

 * status:  closed => reopened
 * resolution:  fixed =>


Comment:

 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 methods.

 In this change I can see that 2011 running on older versions of WP will
 have the showcase script loaded in the footer rather than the header. At
 the time of writing I've only checked the first file.

 To account for the script loading strategies in newer versions of WP, I
 think adding the data via the `$wp_scripts` global will keep the themes
 compatible with older versions of WP. Again using 2011's showcase as an
 example:

 {{{#!php
 <?php
 // Enqueue showcase script for the slider.
 wp_enqueue_script(
         'twentyeleven-showcase',
         get_template_directory_uri() . '/js/showcase.js',
         array( 'jquery' ),
         '20211130',
 );
 // Defer loading of the script in WP 6.3+.
 $wp_scripts->add_data( 'twentyeleven-showcase', 'strategy', 'defer' );
 }}}

 I've reopened this to work on a PR.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59316#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list