[wp-trac] [WordPress Trac] #57864: Defer register inline script in WP_Widget
WordPress Trac
noreply at wordpress.org
Fri Mar 3 17:24:28 UTC 2023
#57864: Defer register inline script in WP_Widget
--------------------------+-----------------------------
Reporter: spacedmonkey | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: 4.8.1
Severity: normal | Keywords:
Focuses: performance |
--------------------------+-----------------------------
In the widget classes, WP_Widget_Custom_HTML and WP_Widget_Text, the
method `_register_one` is called. This method registered a inline script
like this.
{{{#!php
wp_add_inline_script( 'text-widgets', sprintf(
'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) )
);
}}}
{{{#!php
wp_add_inline_script( 'custom-html-widgets', sprintf(
'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base
) ) );
}}}
This results in a script registering. However, this inline script is not
used, unless script is loaded in `admin_print_scripts-widgets.php` hook.
This inline script being registered like this, means that when the widget
is registered, this inline script is registered as well. In my use page
types, this inline script serves no purpose and hiders performance.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57864>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list