#57864 closed enhancement (fixed)
Defer register inline script in WP_Widget
Reported by: | spacedmonkey | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | 4.8.1 |
Component: | Widgets | Keywords: | has-patch |
Focuses: | performance | Cc: |
Description
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.
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
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.
Attachments (2)
Change History (11)
This ticket was mentioned in PR #4170 on WordPress/wordpress-develop by @spacedmonkey.
19 months ago
#1
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/57864
@spacedmonkey commented on PR #4170:
18 months ago
#4
@felixarntz Actioned feedback and these and seeing performance improves still.
@spacedmonkey commented on PR #4170:
18 months ago
#8
Committed
#9
@
18 months ago
As part of investigating #57916, I found that this enhancement is particularly beneficial for widgets_init
performance, and it also improves overall performance slightly, which is great to see. Details in https://core.trac.wordpress.org/ticket/57916#comment:12.
I don't think it should be backported since it doesn't fix any 6.2 regression, but rather is a new performance enhancement, and the win is also not large enough to justify backporting. But it's great that you caught this, it is indeed somehow indirectly contributing to the WP 6.2 slowdown of widgets_init
.
Before, see red square