Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#5003 closed enhancement (fixed)

WP_Scripts::print_scripts() is overly complicated

Reported by: mdawaffe Owned by: mdawaffe
Milestone: 2.3 Priority: normal
Severity: normal Version: 2.2.3
Component: General Keywords: has-patch needs-testing
Focuses: Cc:


WP_Scripts::print_scripts() calls two recursive functions.

  1. WP_Scripts::all_deps() builds a hierarchical array of dependencies.
  2. WP_Scripts::_print_scripts() reads that hierarchical array and echoes out a correctly ordered list of script tags.

The function should instead call one recursive function that builds a correctly ordered array of scripts. That simple array can then be processed non-recursively.

The attached also adds a new filter, print_scripts_array that could be used to do final post-processing of the scripts to deal with things WP_Script's naive dependency system can't do. Example: if prototype and jQuery are loaded on the same page, prototype should come first.

It could use some testing.

Attachments (1)

5003.diff (4.1 KB) - added by mdawaffe 8 years ago.
replaced bad attachment

Download all attachments as: .zip

Change History (6)

comment:1 @mdawaffe8 years ago

  • Owner changed from anonymous to mdawaffe
  • Status changed from new to assigned

It'd be nice if this could make it into 2.3 since jQuery 1.1.4 deals with the $ v. jQuery via noConflict() situation slightly differently than 1.1.3 does. This difference makes the above example (including prototype before jQuery) more urgent.

It's not strictly necessary for 2.3, though, since plugins and core can ensure prototype is loaded before jQuery by adjusting hook priorities.

comment:2 @mdawaffe8 years ago

  • Keywords has-patch needs-testing added

@mdawaffe8 years ago

replaced bad attachment

comment:3 @ryan8 years ago

  • Milestone changed from 2.4 to 2.3

comment:4 @ryan8 years ago

We can give it a try in RC1 and see how it handles.

comment:5 @ryan8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6133]) Script loader cleanup from mdawaffe. fixes #5003

Note: See TracTickets for help on using tickets.