[wp-trac] [WordPress Trac] #59599: Possible performance regression: script strategy `defer` with dependent in footer

WordPress Trac noreply at wordpress.org
Thu Oct 12 17:48:15 UTC 2023


#59599: Possible performance regression: script strategy `defer` with dependent in
footer
------------------------------------+--------------------------
 Reporter:  adamsilverstein         |       Owner:  (none)
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  6.4
Component:  Script Loader           |     Version:  6.3
 Severity:  normal                  |  Resolution:
 Keywords:  dev-feedback has-patch  |     Focuses:  performance
------------------------------------+--------------------------

Comment (by adamsilverstein):

 Posted a potential fix in [attachment:"58599.diff"].

 This could probably use some unit tests to confirm the behavior.

 I tested manually by adding two dummy scripts and experimenting with their
 'in_footer' settings:


 {{{#!php
 <?php
 // Register a dummy script that depends on jquery-blockui, forcing that
 script to be non-deferrable.
 wp_enqueue_script(
         'script-a',
         plugin_dir_url( __FILE__ ) . 'assets/script-a.js',
         array( ),
         '1.0.0',
         array( 'strategy'  => 'defer' ) // Placing this script in the
 header.
 );
 wp_enqueue_script(
         'script-b',
         plugin_dir_url( __FILE__ ) . 'assets/script-b.js',
         array( 'script-a' ),
         '1.0.0',
         array( 'strategy'  => 'blocking', 'in_footer' => true ) // Placing
 this script in the footer.
 );

 }}}

 for script b, I tried with these values for `in_footer`:
 - `array( 'strategy'  => 'blocking', 'in_footer' => true )` - both scripts
 output in footer, neither deferred
 - `array( 'strategy'  => 'defer', 'in_footer' => true )` - script a in
 header, script b in footer, both deferred
 - true - both scripts output in footer, neither deferred
 - false -  script a and b in header, neither deferred

 That final scenario is the worst case, but is consistent with current
 behavior and is expected and I feel acceptable.

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


More information about the wp-trac mailing list