[wp-trac] [WordPress Trac] #60240: Script Modules API: Move the modules to the footer in classic themes

WordPress Trac noreply at wordpress.org
Wed Jan 24 09:59:12 UTC 2024


#60240: Script Modules API: Move the modules to the footer in classic themes
-------------------------------------------------+-------------------------
 Reporter:  luisherranz                          |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Script Loader                        |     Version:
 Severity:  major                                |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:  javascript
  testing-info                                   |
-------------------------------------------------+-------------------------

Comment (by luisherranz):

 Oh, sure.

 To check that this fixes the order of the import map:

 1- Create a new plugin with three files:

 test-plugin/test.php

     <?php
     /*
     Plugin Name: Test Script Modules
     Version: 1.0.0
     */
     wp_register_script_module(
     'bar',
     plugins_url( '/bar.js', __FILE__ )
     );
     wp_enqueue_script_module(
     'foo',
     plugins_url( '/foo.js', __FILE__ ),
     array( 'bar' )
     );

 test-plugin/foo.js

     import bar from 'bar';
     bar();

 test-plugin/bar.js

     export default function bar() {
     console.log( 'bar' );
     }

 2- Activate the plugin.
 3- Open the site (frontend).
 4- Check that `"bar"` was printed in the console.

 To check that this fixes the positioning of the scripts/link in the
 classic themes:

 1- Load a block theme.
 2- Check that the scripts with `type="importmap"` and `type="module"`, and
 the link with `rel="modulepreload"` are printed in the head.
 3- Load a classic theme.
 2- Check that the scripts with `type="importmap"` and `type="module"`, and
 the link with `rel="modulepreload"` are printed in the footer.

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


More information about the wp-trac mailing list