XPaths for elements in URL Metrics can omit index for children of BODY to avoid needing to vary URL Metrics by whether a user is logged-in #1787
Labels
[Plugin] Optimization Detective
Issues for the Optimization Detective plugin
[Type] Enhancement
A suggestion for improvement of an existing feature
Milestone
Discussed initially at #1759 (comment)
URL Metrics currently are varied by whether or not a user is logged-in. This is all of the XPaths used on the page differ based on whether or not the admin bar is present, since the element index is included with each element reference. For example, the following is the XPath for the first
IMG
in post content when logged-out vs logged-in:The difference is that when logged-in, two new elements appear at the beginning of the
BODY
:SCRIPT
coming fromwp_customize_support_script()
(for admin users).DIV#wpadminbar
for the admin bar.These result in the page wrapper
DIV
's XPath going*[1][self::DIV]
to*[3][self::DIV]
.The purpose of the element index in the XPath is to differentiate one element from another. If there are 3
IMG
tags appearing next to each other in a post, and only the first is LCP, then it's important to be able to uniquely reference thatIMG
. Nevertheless, at the root level of a page (when directly under theBODY
) it is highly unlikely for there to be any such ambiguity. This is because themes almost always wrap the content betweenwp_body_open()
andwp_footer()
. Classic themes typically wrap the content in aDIV#page
element, whereas Block Themes always wrap the content in aDIV.wp-site-blocks
element. The only exception in core is that the Twenty Twenty theme which does not have one root wrapper but instead has aHEADER
,MAIN
, andFOOTER
at the root. In this case too there is no possibility for ambiguity since these three are unique.So I suggest we do the following:
od_get_normalized_query_vars()
:performance/plugins/optimization-detective/storage/data.php
Lines 80 to 83 in b6e5c5a
HTML
,BODY
, and children directly under theBODY
. So the XPaths above would become the following:wp_body_open()
(e.g. thewp_customize_support_script()
). With the presence/absence of such elements printed atwp_body_open
(andwp_footer
) eliminated, we can eliminate this code fromod_can_optimize_response()
which would resolve Optimization Detective should be enabled by default for admins #1425:performance/plugins/optimization-detective/optimization.php
Lines 121 to 126 in b6e5c5a
OD_Element
to convert to this new format so existing optimizations will continue to apply based on old URL Metrics:Then in the next release or two we can eliminate this code since the old URL Metrics should have all been purged by then.
The text was updated successfully, but these errors were encountered: