[wp-trac] [WordPress Trac] #26886: wp_enqueue_script doesn't load all scripts

WordPress Trac noreply at wordpress.org
Thu Oct 16 15:43:30 UTC 2014


#26886: wp_enqueue_script doesn't load all scripts
-------------------------------+-----------------------
 Reporter:  alfredocubitos     |       Owner:
     Type:  defect (bug)       |      Status:  reopened
 Priority:  normal             |   Milestone:
Component:  Script Loader      |     Version:  3.8
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+-----------------------
Changes (by kraterdesign):

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


Comment:

 I just ran into this bug and also found why and when it happens.

 In latest WP, check out function _print_scripts() in script-loader.php
 (line 848-849 in current v4.0)

 {{{#!php
                 $concat = str_split( $concat, 128 );
                 $concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat
 );
 }}}

 That first line splits the string $concat into an array of strings of max.
 length 128. So when you have a string of comma-separated script names that
 exceeds 128 characters, the script name that crosses the 128th character
 boundary inside the string, will be cut in two and thus not be loaded.

 As you can see this only happens when there are a lot of admin scripts
 loaded. Ie. when concatenated into a comma-separated they make up a string
 with a total length larger than 128 chars.

 When I ran into this, the concatenated end result reads:
 {{{
 /wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-
 migrate,underscore,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse
 ,jquery-ui-sortable,jquery-ui-datepic&load%5B%5D=ker,json2,jquery-ui-
 draggable&ver=4.0
 }}}

 ... in this case effectively not loading jquery-ui-datepicker.

 I'm guessing this was done to make sure the parameter value length never
 exceeds 128 chars. Here's a different way to do the same and not break
 script names.

 {{{#!php
                 $concat = explode( $concat, ',' );
                 $concats_128char = array();
                 $concat_temp = '';
                 foreach ( $concat as $c ) {
                         if ( strlen( $concat_temp . ',' . $c ) > 128 ) {
                                 $concats_128char[] = $concat_temp;
                                 $concat_temp = '';
                         }
                         $concat_temp .= ',' . $c;
                         $concat_temp = trim( $concat_temp, ',' );
                 }
                 $concats_128char[] = $concat_temp;
                 $concat = 'load%5B%5D=' . implode( '&load%5B%5D=',
 $concats_128char );
 }}}

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


More information about the wp-trac mailing list