[wp-trac] [WordPress Trac] #36392: wp_add_inline_script() breaks script dependency order when using script loader (no SCRIPT_DEBUG)

WordPress Trac noreply at wordpress.org
Fri Apr 8 21:31:15 UTC 2016


#36392: wp_add_inline_script() breaks script dependency order when using script
loader (no SCRIPT_DEBUG)
--------------------------------------+-------------------------
 Reporter:  westonruter               |       Owner:  swissspidy
     Type:  defect (bug)              |      Status:  assigned
 Priority:  high                      |   Milestone:  4.5
Component:  Script Loader             |     Version:  trunk
 Severity:  major                     |  Resolution:
 Keywords:  has-unit-tests has-patch  |     Focuses:
--------------------------------------+-------------------------

Comment (by swissspidy):

 > All of these scripts are concatenated by default. How is concatenating
 supposed to work in this case? The only way I see is to "break" the
 concatenation and take them and all their dependencies out, which seems to
 be what we are trying to do now.

 That's correct. However, `_print_scripts()` is currently hardcoded to
 print all concatenated scripts first and the rest afterwards. One way to
 implement this is to add `load-scripts.php?…` via `$wp_scripts->add(…)`
 multiple times. That way you'd get as much concatenation as possible, but
 with dependencies in the right order.

 > If the "before" and "after" scripts do not have to be right before and
 right after, this can be achieved in couple of different ways.
 `$wp_scripts->localize()` works that way, or scripts can be outputted
 directly on the same hook with lower or higher priority. Then they will be
 before or after all other scripts.

 If we go that route it'd probably very difficult to change behaviour in
 the future if needed. As a developer, I'd expect the order to be more
 accurate since you use `wp_add_inline_script()` per script handle, not
 universally as `wp_add_inline_script( 'do_stuff()', 'before' );`

 > If we *must* have "right before" and right after" scripts, thinking the
 only "sane" way would be to disable concatenating when they are used.
 > Also, looking forward to the time we stop concatenating scripts and
 stylesheets because of HTTP/2 :)

 I explored many options today and everything eventually comes back to
 this. HTTP/2 is an argument as well.

 However, are we confident in disabling concatenating in this case? Will
 this confuse developers expecting concatenated scripts all the time?

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


More information about the wp-trac mailing list