[wp-trac] [WordPress Trac] #27407: wp_enqueue_scripts: jQuery loads in head despite of being included as dependency of another footer script

WordPress Trac noreply at wordpress.org
Fri Mar 21 20:15:55 UTC 2014


#27407: wp_enqueue_scripts: jQuery loads in head despite of being included as
dependency of another footer script
---------------------------+------------------------------
 Reporter:  Marventus      |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Script Loader  |     Version:  trunk
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------

Comment (by bcworkz):

 ::BC waves at Marv
 I get the same thing on r27646 with twentyfourteen. It seems that the load
 in footer parm only applies to the script being registered and can never
 apply to jquery files. Curiously, taking the re-registration idea one more
 step results in jQuery failing to be referenced at all!
 {{{
 function tgi_jquery_in_footer_test() {
     wp_deregister_script("jquery-core");
     wp_deregister_script("jquery-migrate");
     wp_deregister_script("jquery");
     wp_register_script("jquery-core", '/wp-includes/js/jquery/jquery.js',
 array(), "1.11.0", true);
     wp_register_script("jquery-migrate", '/wp-includes/js/jquery/jquery-
 migrate.min.js', array(), "1.2.1", true);
     wp_register_script("jquery", false, array("jquery-core", "jquery-
 migrate"), "1.11.0", true);
     wp_register_script('tgi-jquery-js', "//some/uri/name.js",
 array("jquery"), "0.1", true);
     wp_enqueue_script('tgi-jquery-js');
 }
 add_action('wp_enqueue_scripts', 'tgi_jquery_in_footer_test');
 }}}
 Registering the core and migrate files without the footer parm results in
 proper loading, albeit in the head of course. With the footer parm
 included, the jQuery files are properly placed in the global `$wp_scripts`
 array to facilitate footer loading, however, the references are never
 output for some unknown reason. If this can be resolved, it appears footer
 loading of jQuery would be possible via reregistration.

 This code unsurprisingly loads both scripts in  the footer:
 {{{
 function tgi_jquery_in_footer_test2() {
     wp_register_script('tgi-jquery2-js', "//some/uri/name2.js",
 array("jquery"), "0.1", true);
     wp_register_script('tgi-jquery-js', "//some/uri/name.js", array("tgi-
 jquery2-js"), "0.1", true);
     wp_enqueue_script('tgi-jquery-js');
 }
 add_action('wp_enqueue_scripts', 'tgi_jquery_in_footer_test2');
 }}}
 But removing the footer parm from 'tgi-jquery2-js' causes it to load in
 head again. (Fortunately, removing the footer parm from 'tgi-jquery-js'
 but not 'tgi-jquery2-js' does correctly cause 'tgi-jquery2-js' to be
 loaded in head despite its footer parm.) This demonstrates that the footer
 parm is indeed only applied to the registered script and not dependencies.

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


More information about the wp-trac mailing list