Make WordPress Core

Opened 16 years ago

Closed 3 weeks ago

Last modified 3 weeks ago

#15833 closed defect (bug) (invalid)

Script concatenation fails to take external dependencies into account.

Reported by: jczorkmid Owned by:
Priority: normal Milestone:
Component: Script Loader Version: 3.0
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

Script concatenation places the concatenated script include first, before any scripts loaded separately. If one of the scripts in the concatenation relies on a script outside the concatenation the dependency order is ignored.

When the dependencies are all internal to the concatenation things work fine (for example script4 relies on script3):

  • concat=script1,script2,script3,script4,script5

But when script3 is loaded externally, script4 will break:

  • concat=script1,script2,script4,script5
  • external-script3

This becomes apparent if jQuery is loaded from a non-standard location (via a plugin or the ​code from the Codex) in that the visual editor fails to function correctly because source:/trunk/wp-admin/js/editor.js uses jQuery (which it fails to register as a dependency, see ticket:15830, but when I fixed that locally the results were the same).

I'm working around this in ​Use Google Libraries by globally disabling concatenation, but it would be nice if this was fixed.

If possible, it would be nice if the loader was smart enough to do something like:

  • concat=script1,script2
  • external-script3
  • concat=script4,script5

Or at least flagged the script with the dependency as unsafe for concatenation:

  • concat=script1,script2,script5
  • external-script3
  • script4


Change History (6)

#1 @nacin
16 years ago

  • Milestone Awaiting Review → Future Release

#2 @nacin
13 years ago

  • Component General → Script Loader

#3 @chriscct7
11 years ago

  • Keywords needs-patch added

This ticket was mentioned in ​PR #12449 on ​WordPress/wordpress-develop by ​@sukhendu2002.


4 months ago
#4

  • Keywords has-patch has-unit-tests added; needs-patch removed

#5 @westonruter
3 weeks ago

In 64585:

Script Loader: Retire script and style concatenation.

Scripts and styles in the admin and on the login screen are no longer concatenated through load-scripts.php and load-styles.php. Concatenation paid off when browsers opened few connections per host over HTTP/1.1, but it has long been a source of bugs: dependencies outside the default directories were not honored, SCRIPT_DEBUG and the script_loader_src and style_loader_src filters were ignored, inline styles could be duplicated, and code run by the loaders without WordPress loaded caused fatal errors. It was turned off by default in r64320, once the assets of the next admin screen began to be prefetched in r64120, and this removes what remains.

Every item is now printed as its own tag, and what remains of the concatenation API is deprecated or removed:

  • The properties of WP_Scripts and WP_Styles that held items back for concatenation are deprecated but still declared, so plugins reading or setting them keep working. The do_item() methods no longer check do_concat.
  • The _print_scripts(), _print_styles(), script_concat_settings(), in_default_dir() and WP_Dependencies::get_etag() functions are deprecated.
  • The print_head_scripts, print_footer_scripts, print_admin_styles and print_late_styles filters only decided whether held markup was printed, so they are applied with apply_filters_deprecated() and their return values are ignored.
  • The CONCATENATE_SCRIPTS constant is no longer read.
  • The wp_should_concatenate_admin_scripts() function and its filter, added in r64120 for the transition and never released, are removed.

The loaders now respond with 410 Gone and a one-line plain text explanation, without loading WordPress, so that requests from bots and stale links cost next to nothing. Code written to run inside them without WordPress loaded, such as wp_theme_has_theme_json(), now uses the functions it had avoided, and wp-admin/includes/noop.php no longer defines its stub functions.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/14463.
Follow-up to r10357, r43580, r60719, r62657, r64120, r64320, r64485.

Props westonruter, jonsurrell, peterwilsoncc, azaozz, markhowellsmead, sergiomdgomes, jerclarke, adamsilverstein, sukhendu2002, adnan007, momo360modena, desrosj, welcher.
See #15833, #36448, #36449, #36779, #43825, #45008, #47322, #52879, #63908, #64087, #65515.
Fixes #57548.

#6 @westonruter
3 weeks ago

  • Milestone Future Release
  • Resolution → invalid
  • Status new → closed

Closing as obsolete now that script concatenation has been retired in #57548.

Last edited 3 weeks ago by westonruter (previous) (diff)
Note: See TracTickets for help on using tickets.