[wp-trac] [WordPress Trac] #26886: wp_enqueue_script doesn't load all scripts
WordPress Trac
noreply at wordpress.org
Wed Feb 18 19:16:13 UTC 2015
#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 alturic):
* status: closed => reopened
* resolution: worksforme =>
Comment:
Replying to [comment:4 kraterdesign]:
> 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 );
> }}}
I know this is super out-dated, but in my regard on WP 4.1 this is still
an issue. Sure it's my theme calling a ton of scripts but it's fixed by
changing $concat = str_split( $concat, 128 ); to something higher? I
changed it to $concat = str_split( $concat, 3000 ); and everything SEEMS
to work fine, I don't have the problem anymore or anything but a.) it's
editing a core file (blah) and b.) I'm unsure what all can happen by
simply doing that.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/26886#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list