[wp-trac] [WordPress Trac] #48880: Using JSON.parse instead of an actual object literal when localizing scripts
WordPress Trac
noreply at wordpress.org
Thu Dec 5 00:34:18 UTC 2019
#48880: Using JSON.parse instead of an actual object literal when localizing
scripts
-------------------------------------+-----------------------------
Reporter: naxvog | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: 5.3
Severity: normal | Keywords:
Focuses: javascript, performance |
-------------------------------------+-----------------------------
As the V8 team at Google stated in their "The cost of JavaScript in 2019"
[https://v8.dev/blog/cost-of-javascript-2019#json]" blog post using
{{{JSON.parse()}}} is generally faster (~18%) for configuration object
literals such as the output of the localize method of the WP_Scripts
class.
As the output of the localize method is already rendered using
{{{wp_json_encode()}}} the change would be quite trivial and backward
compatible.
Added a diff with additional changes to the block editor init script using
the same method.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48880>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list