-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unclear purpose for tag visitors returning true or false in Optimization Detective #1342
Comments
All core output images will have decoding=async by default.
That makes sense. |
Yes, this is just an example. |
What determines whether the tag needs to be tracked in the URL Metrics? If any modifications have been made by the visitor at all, or are there specific types of changes that need to return In other words, would we want to return |
The tag would need to be tracked in URL metrics if the tag visitor needs to obtain any metrics for the element in the URL metrics. In the example case here with performance/plugins/embed-optimizer/class-embed-optimizer-tag-visitor.php Lines 37 to 120 in 0ffc414
|
So basically, if a tag visitor accesses |
So that's why I mentioned this:
So we could detect whether a tag visitor accesses |
I like the idea of making this behavior explicit. I don't fully understand the intended semantics of the current API, but I wonder if we need to modify the API for registering visitors to include an signal (e.g., property, arg, option, etc) whether it uses URL metrics? That way we could separate the return value indicating whether the visitor optimization was performed from whether the tag needs to be tracked for user metrics. |
When registering a tag visitor in Optimization Detective, the callable must return a boolean. When the boolean returns
true
, then this is an indication that the tag was indeed "visited" or rather that the visitor is relevant to the current tag. For example:Clearly this visitor should return
false
if the current tag is not anIMG
. But should it still also returnfalse
if it already has adecoding=async
attribute?In reality, when a visitor returns
true
this is a signal for whether or not the tag should be captured to be stored in the URL Metrics:performance/plugins/optimization-detective/optimization.php
Lines 180 to 192 in 4ff08f9
So when a visitor returns
true
then this means that$did_visit
will betrue
and if the URL Metrics for current URL are not complete (if$needs_detection
isfalse
), then the effect is that it will add thedata-od-xpath
attribute to the tag. What does this do? It means that whendetect.js
runs, it will include the element among all of the elements for which it captures metrics, including via IntersectionObserver and web-vitals.js:performance/plugins/optimization-detective/detect.js
Line 242 in 726f10c
performance/plugins/optimization-detective/detect.js
Lines 285 to 287 in 726f10c
However, in the case above for a tag visitor that just makes sure that all
img
tags havedecoding=async
, there is no need for this tag to ever be captured in the URL metrics because the URL metrics do not impact how the applied optimization in any way. This is in contrast with what Image Prioritizer does with applying lazy-loading and fetchpriority=high, where it depends on the URL Metrics to know what optimization to perform. Embed Optimizer also depends on URL Metrics to know whether an embed should be lazy-loaded or instead should have preconnect links added. Conversely, the auto-sizes integration in #1322 doesn't depend on the URL Metrics and so at present its tag visitor could always return false.In short, I think the explanation of what the boolean means being returned from a tag visitor. It's not whether the tag was visited, but rather whether or not the tag needs to be tracked in the URL Metrics.
It could also be possible to automatically detect whether or not a tag visitor depends on URL metrics by detecting whether or not it accessed the
$context->url_metrics_group_collection
. If so, then this would be a signal that indeed the tag should be tracked in the URL metrics, and the return value of the tag visitor could be eliminated entirely. However, this could be a bit too sophisticated.The text was updated successfully, but these errors were encountered: