[wp-trac] [WordPress Trac] #25277: WP_scripts does not allow to add data after the enque has been added to HTML

WordPress Trac noreply at wordpress.org
Tue Jan 6 01:47:35 UTC 2015


#25277: WP_scripts does not allow to add data after the enque has been added to
HTML
-----------------------------+-----------------------------
 Reporter:  hakre            |       Owner:  wonderboymusic
     Type:  feature request  |      Status:  reopened
 Priority:  normal           |   Milestone:  4.2
Component:  Script Loader    |     Version:  3.6
 Severity:  normal           |  Resolution:
 Keywords:  has-patch        |     Focuses:
-----------------------------+-----------------------------

Comment (by wonderboymusic):

 yeah.... so the idea was just to allow something to output after, since
 you can currently only register something to output before ....

 Where this could be useful, if the result ends up being:

 {{{
 <script>
 var settingsBlob = {
     apiKey: 'q1w2e3r4t5'
 };
 </script>
 <script src="lib/api.js"></script>
 <script>
 new API( settings );
 </script>
 }}}

 This works great when the file in the middle doesn't produce side-effects
 (most of the WP files produce side-effects ... )

 Passing in JS as a string to `$wp_scripts->add_data()` sucks, might better
 if it also took a `callable`, which `wp_localize_script()` now does.

 When concatenation is used, the choices are:
 * Output the data right after the script in the concat blob
 * Output all data at once (which I have done) - once again, could get
 weird if files produce side effects.

 Another potential issue - if some enqueues the script but doesn't want the
 data.

 I'll leave the decision here to you @azaozz. I am not married to this, a
 revert would not hurt my feelings.

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


More information about the wp-trac mailing list