Skip to content

Commit

Permalink
Merge pull request #1276 from WordPress/publish/image-prioritizer
Browse files Browse the repository at this point in the history
Finalize Image Prioritizer 0.1.0 and Optimization Detective 0.3.0 for standalone plugin releases
  • Loading branch information
westonruter authored Jun 5, 2024
2 parents bf5e1ad + 7f68623 commit 625a713
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Image Prioritizer: IP_Background_Image_Styled_Tag_Visitor class
*
* @package image-prioritizer
* @since n.e.x.t
* @since 0.1.0
*/

// Exit if accessed directly.
Expand All @@ -14,7 +14,7 @@
/**
* Visitor for the tag walker that optimizes elements with background-image styles.
*
* @since n.e.x.t
* @since 0.1.0
* @access private
*/
final class Image_Prioritizer_Background_Image_Styled_Tag_Visitor extends Image_Prioritizer_Tag_Visitor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Image Prioritizer: IP_Img_Tag_Visitor class
*
* @package image-prioritizer
* @since n.e.x.t
* @since 0.1.0
*/

// Exit if accessed directly.
Expand All @@ -14,7 +14,7 @@
/**
* Visitor for the tag walker that optimizes IMG tags.
*
* @since n.e.x.t
* @since 0.1.0
* @access private
*/
final class Image_Prioritizer_Img_Tag_Visitor extends Image_Prioritizer_Tag_Visitor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Image Prioritizer: IP_Image_Tag_Visitor class
*
* @package image-prioritizer
* @since n.e.x.t
* @since 0.1.0
*/

// Exit if accessed directly.
Expand All @@ -14,7 +14,7 @@
/**
* Visitor for the tag walker that optimizes image tags.
*
* @since n.e.x.t
* @since 0.1.0
* @access private
*/
abstract class Image_Prioritizer_Tag_Visitor {
Expand Down
6 changes: 3 additions & 3 deletions plugins/image-prioritizer/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Helper functions for Image Prioritizer.
*
* @package image-prioritizer
* @since n.e.x.t
* @since 0.1.0
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -15,7 +15,7 @@
*
* See {@see 'wp_head'}.
*
* @since n.e.x.t
* @since 0.1.0
*/
function image_prioritizer_render_generator_meta_tag(): void {
// Use the plugin slug as it is immutable.
Expand All @@ -25,7 +25,7 @@ function image_prioritizer_render_generator_meta_tag(): void {
/**
* Registers tag visitors for images.
*
* @since n.e.x.t
* @since 0.1.0
*
* @param OD_Tag_Visitor_Registry $registry Tag visitor registry.
* @param OD_URL_Metrics_Group_Collection $url_metrics_group_collection URL Metrics Group Collection.
Expand Down
2 changes: 1 addition & 1 deletion plugins/image-prioritizer/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Hook callbacks used for Image Prioritizer.
*
* @package image-prioritizer
* @since n.e.x.t
* @since 0.1.0
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand Down
6 changes: 4 additions & 2 deletions plugins/image-prioritizer/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Requires PHP: 7.2
Stable tag: 0.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, images
Tags: performance, optimization, image, lcp, lazy-load

Optimizes LCP image loading with `fetchpriority=high` and applies image lazy-loading by leveraging client-side detection with real user metrics.

Expand All @@ -24,7 +24,9 @@ In addition to prioritizing the loading of the LCP image, this plugin also optim

If an image does not appear in the initial viewport for any of these viewport groups, then `loading=lazy` is added to the `img` element.

Note that by default, URL Metrics are not gathered for administrator users, since they are not normal site visitors, and it is likely that additional elements will be present on the page which are not also shown to non-administrators.
👉 **Note:** This plugin optimizes pages for actual visitors, and it depends on visitors to optimize pages (since URL metrics need to be collected). As such, you won't see optimizations applied immediately after activating the plugin. And since administrator users are not normal visitors typically, optimizations are not applied for admins by default.

There are currently **no settings** and no user interface for this plugin since it is designed to work without any configuration.

This plugin requires the [Optimization Detective](https://wordpress.org/plugins/optimization-detective/) plugin as a dependency. Please refer to that plugin for additional background on how this plugin works as well as additional developer options.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public function append_body_html( string $html ): bool {
* This is a wrapper around the underlying WP_HTML_Tag_Processor method of the same name since only a limited number of
* methods can be exposed to prevent moving the pointer in such a way as the breadcrumb calculation is invalidated.
*
* @since n.e.x.t
* @since 0.3.0
* @see WP_HTML_Tag_Processor::get_tag()
*
* @return string|null Name of currently matched tag in input HTML, or `null` if none found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Optimization Detective: OD_Preload_Link_Collection class
*
* @package optimization-detective
* @since n.e.x.t
* @since 0.3.0
*/

// Exit if accessed directly.
Expand All @@ -29,7 +29,7 @@
* as: 'audio'|'document'|'embed'|'fetch'|'font'|'image'|'object'|'script'|'style'|'track'|'video'|'worker'
* }
*
* @since n.e.x.t
* @since 0.3.0
* @access private
*/
final class OD_Preload_Link_Collection implements Countable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Optimization Detective: OD_Tag_Visitor_Registry class
*
* @package optimization-detective
* @since n.e.x.t
* @since 0.3.0
*/

// Exit if accessed directly.
Expand All @@ -18,7 +18,7 @@
*
* @implements IteratorAggregate<string, TagVisitorCallback>
*
* @since n.e.x.t
* @since 0.3.0
* @access private
*/
final class OD_Tag_Visitor_Registry implements Countable, IteratorAggregate {
Expand Down
2 changes: 1 addition & 1 deletion plugins/optimization-detective/optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function od_optimize_template_output_buffer( string $buffer ): string {
/**
* Fires to register tag visitors before walking over the document to perform optimizations.
*
* @since n.e.x.t
* @since 0.3.0
*
* @param OD_Tag_Visitor_Registry $tag_visitor_registry Tag visitor registry.
* @param OD_URL_Metrics_Group_Collection $group_collection URL Metrics Group collection.
Expand Down
17 changes: 11 additions & 6 deletions plugins/optimization-detective/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Requires PHP: 7.2
Stable tag: 0.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance
Tags: performance, optimization, rum

Provides an API for leveraging real user metrics to detect optimizations to apply on the frontend to improve page performance.

Expand All @@ -27,13 +27,13 @@ At the core of Optimization Detective is the “URL Metric”, information about

URL Metrics have a “freshness TTL” after which they will be stale and the JavaScript will be served again to start gathering metrics again to ensure that the right elements continue to get their loading prioritized. When a URL Metrics custom post type hasn't been touched in a while, it is automatically garbage-collected.

Prioritizing the loading of images which are the LCP element is only the first optimization implemented as a proof of concept for how other optimizations might also be applied. See a [list of issues](https://github.com/WordPress/performance/labels/%5BPlugin%5D%20Optimization%20Detective) for planned additional optimizations which are only feasible with the URL Metrics RUM data.
👉 **Note:** This plugin optimizes pages for actual visitors, and it depends on visitors to optimize pages (since URL metrics need to be collected). As such, you won't see optimizations applied immediately after activating the plugin (and dependent plugin(s)). And since administrator users are not normal visitors typically, optimizations are not applied for admins by default (but this can be overridden with the `od_can_optimize_response` filter below). URL metrics are not collected for administrators because it is likely that additional elements will be present on the page which are not also shown to non-administrators, meaning the URL metrics could not reliably be reused between them.

Note that by default, URL Metrics are not gathered for administrator users, since they are not normal site visitors, and it is likely that additional elements will be present on the page which are not also shown to non-administrators.
There are currently **no settings** and no user interface for this plugin since it is designed to work without any configuration.

When the `WP_DEBUG` constant is enabled, additional logging for Optimization Detective is added to the browser console.

= Filters =
= Hooks =

**Filter:** `od_breakpoint_max_widths` (default: [480, 600, 782])

Expand Down Expand Up @@ -68,7 +68,9 @@ Filters the sample size for a breakpoint's URL metrics on a given URL. The sampl

`
<?php
add_filter( 'od_url_metrics_breakpoint_sample_size', function (): int { return 1; } );
add_filter( 'od_url_metrics_breakpoint_sample_size', function (): int {
return 1;
} );
`

**Filter:** `od_url_metric_storage_lock_ttl` (default: 1 minute)
Expand Down Expand Up @@ -97,7 +99,7 @@ Filters the time window between serve time and run time in which loading detecti

**Filter:** `od_template_output_buffer` (default: the HTML response)

Filters the template output buffer prior to sending to the client. This filter is added to implement #43258.
Filters the template output buffer prior to sending to the client. This filter is added to implement [#43258](https://core.trac.wordpress.org/ticket/43258) in WordPress core.

== Installation ==

Expand Down Expand Up @@ -135,6 +137,8 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu

= 0.3.0 =

* The image optimization features have been split out into a new dependent plugin called [Image Prioritizer](https://wordpress.org/plugins/image-prioritizer/), which also now optimizes image lazy-loading. ([1088](https://github.com/WordPress/performance/issues/1088))

= 0.2.0 =

**Enhancements**
Expand Down Expand Up @@ -163,4 +167,5 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu
== Upgrade Notice ==

= 0.3.0 =

Image loading optimizations have been moved to a new dependent plugin called Image Prioritizer. The Optimization Detective plugin now serves as a dependency.

0 comments on commit 625a713

Please sign in to comment.