-
Notifications
You must be signed in to change notification settings - Fork 140
Description
I'm currently analyzing URLs in HTTP Archive which have Image Prioritizer active. My crawler is successfully able to exclude URLs on sites which don't have the REST API available for unauthenticated requests thanks to #1762 which added rest_api_unavailable to the meta generator tag:
performance/plugins/optimization-detective/helper.php
Lines 70 to 80 in 69b7a14
| function od_render_generator_meta_tag(): void { | |
| // Use the plugin slug as it is immutable. | |
| $content = 'optimization-detective ' . OPTIMIZATION_DETECTIVE_VERSION; | |
| // Indicate that the plugin will not be doing anything because the REST API is unavailable. | |
| if ( od_is_rest_api_unavailable() ) { | |
| $content .= '; rest_api_unavailable'; | |
| } | |
| echo '<meta name="generator" content="' . esc_attr( $content ) . '">' . "\n"; | |
| } |
However, I'm realizing there are other bits of meta which would be very helpful when analyzing sites. For example, even though the REST API may be available, it may be that detection is broken for another reason, like when an optimization plugin attempts to delay loading the detect.js module (#1890). In this case, the result is that there will be data-od-xpath attributes on the page, but there will never be any URL Metrics collected. I'm sniffing for this by checking to see if Image Prioritizer is adding data-od-unknown-tag attributes to IMG tags while also there not being any preload links being added (LINK[data-od-added-tag]) or other mutations being made to attributes which depend on URL Metrics being present (e.g. data-od-added-*, data-od-replaced-*, data-od-removed-*, data-od-fetchpriority-already-added, etc).
Instead of sniffing based on the attributes, it would be useful if the meta generator tag was amended with the status of the URL Metrics. Granted, this information could be scraped from the urlMetricGroupStatuses passed to the detection module; however, this depends on the script module being present on the page, and an optimization plugin may remove it or concatenate it with another script, for example. So it would be useful to have this information in a consistent place for ease of reference. When analyzing sites using Image Prioritizer, we can skip looking at URLs that don't have URL Metrics collected for the mobile and desktop viewport groups, for example.
The information we'd want to expose includes what the viewport groups are, if they are complete, or else if they are at least populated.
So maybe something like this:
<meta name="generator" content="optimization-detective 1.0.0; url_metric_groups={0:complete, 480:empty, 600:populated, 782:complete}"
This means:
- Viewport group 0-480 is complete
- Viewport group 480-600 is empty
- Viewport group 600-782 is populated (has at least one URL Metric, but may be stale)
- Viewport group >782 is complete
As for how this information would be populated, it would have to be done in od_optimize_template_output_buffer() inside the do/while loop. For exmaple:
diff --git a/plugins/optimization-detective/optimization.php b/plugins/optimization-detective/optimization.php
index e3a7bbddf..6b6b42cb1 100644
--- a/plugins/optimization-detective/optimization.php
+++ b/plugins/optimization-detective/optimization.php
@@ -310,6 +310,7 @@ function od_optimize_template_output_buffer( string $buffer ): string {
// Whether we need to add the data-od-xpath attribute to elements and whether the detection script should be injected.
$needs_detection = ! $group_collection->is_every_group_complete();
+ $did_amend_meta_generator = false;
do {
// Never process anything inside NOSCRIPT since it will never show up in the DOM when scripting is enabled, and thus it can never be detected nor measured.
// Similarly, elements in the Admin Bar are not relevant for optimization, so this loop ensures that no tags in the Admin Bar are visited.
@@ -321,6 +322,16 @@ function od_optimize_template_output_buffer( string $buffer ): string {
continue;
}
+ if (
+ ! $did_amend_meta_generator &&
+ 'META' === $processor->get_tag() &&
+ 'generator' === $processor->get_attribute( 'name' ) &&
+ str_starts_with( (string) $processor->get_attribute( 'content' ), 'optimization-detective' )
+ ) {
+ // TODO: Append the content attribute with information from $group_collection.
+ $did_amend_meta_generator = true;
+ }
+
$tracked_in_url_metrics = false;
$processor->set_bookmark( $current_tag_bookmark ); // TODO: Should we break if this returns false?Metadata
Metadata
Assignees
Labels
Type
Projects
Status