[wp-trac] [WordPress Trac] #58873: Add function to pass variables to scripts

WordPress Trac noreply at wordpress.org
Sat Aug 16 10:07:54 UTC 2025


#58873: Add function to pass variables to scripts
-----------------------------+-----------------------
 Reporter:  apedog           |       Owner:  (none)
     Type:  feature request  |      Status:  reopened
 Priority:  normal           |   Milestone:
Component:  Script Loader    |     Version:  5.7
 Severity:  normal           |  Resolution:
 Keywords:  2nd-opinion      |     Focuses:
-----------------------------+-----------------------
Changes (by jonsurrell):

 * keywords:   => 2nd-opinion
 * status:  closed => reopened
 * resolution:  worksforme =>


Comment:

 Thanks @westonruter, I didn't know that!

 For what it's worth, I much prefer the
 [https://developer.wordpress.org/reference/hooks/script_module_data_module_id/
 "pull" style of passing data that's used by script modules with the
 script_module_data_{$module_id} filter.] Some advantages:

 - The browser does not evaluate the script contents _at all_ because it's
 not a JavaScript script tag.
 - The data is parsed and used _on demand_ when necessary by the script
 that requires it.
 - No use of a shared global JavaScript namespace.

 There's potential for improvement for classic scripts, but I'd be very
 wary of adding a ''third'' pattern for passing data to classic scripts. If
 anything, we could consider porting the script modules form to scripts to
 avoid a new pattern, but share an existing pattern.

 I'll reopen for a second opinion.

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


More information about the wp-trac mailing list