-
Notifications
You must be signed in to change notification settings - Fork 109
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
Auto Sizes should extend Optimization Detective to add sizes=auto when also lazy-loading images #1099
Comments
Thanks @westonruter. Ideally, I would think that any plugins that are filtering the lazy loading value for images would run prior to the logic that determines whether those images would also make use of auto-sizes. Do you foresee a reason why the processing to add lazy loading from the Optimization Detective would not be able to run before the sizes value is calculated? |
@joemcgill The processing done by Optimization Detective happens after the template has been fully rendered, so long after filters like |
You do understand the question, but I don't think I understand the expected usage of the API in that case 😆. I had assumed that the logic for adding optimizations like lazy-loading, auto-sizes, fetch priority, etc., would be able to be filtered using data collected from the Optimization Detective, rather than needing to add a post-processing step after WP has completed rendering. |
@joemcgill Ah, I see. The optimization needs to be done in the post-processing step because only at that point are we able to see if a given rendered image is the same image that was previously detected, since it relies on matching them with XPaths. Additionally, optimizations can be performed for any arbitrary markup, not depending on filters that WordPress provides during template generation. |
Got it. I think the tricky part here is that the auto-sizes plugin will not have any way of knowing whether some other feature is modifying lazy-loading attributes of images after it is finished its processing, which could be true for more than just plugins making use of the Optimization Detective to add post-processing. Can you point to where you are applying this post processing? Perhaps the auto-sizes plugin could preemptively move processing to the same place? |
@joemcgill Yeah, I think in practice it Auto Sizes would continue doing what it is doing today, by injecting See the current code for the post-processing, although this will be refactored as part of splitting out into Image Prioritizer (#1088). |
Ah, I see. You've implemented output buffering as in https://core.trac.wordpress.org/ticket/43258 in order to handle the post-processing. Very cool! I'm unsure if we should try to simply hook somewhere into the post-processing that OD is doing or if we would be better off trying to support any use cases where images might end up with different lazy-loading attributes based on output buffering. For example, some plugins are likely rendering their own images and applying lazy loading using non-standard ways. It would be great if we could account for those use cases and apply auto-sizes in those cases as well. |
Wouldn't the output buffer post-processing account for any use case, whether images are generated the traditional way or whether they are added in non-standard ways? |
Yes, OD's output buffering should catch all cases. However, I was thinking about this in a couple of different ways: If the auto-sizes plugin bundled the OD API, then we could just use that functionality to apply auto-sizes to all lazy loaded images. However, output buffering is not compatible with all setups due to potential conflicts with other plugins that also use an output buffering technique or prematurely flush all buffers. Alternately, we could integrate with any plugins that are using OD (e.g. the future Image, by adding a callback to one of ODs hooks to do some post-processing cleanup. However, this would only fix compatibility issues introduced by ODs post-processing and not any other plugins that are doing similar things to add lazy-loading after WP's default image processing is done. Given that the purpose of |
Do you have any example of this? I've heard this raised before as a problem, but I haven't seen it in actual plugins. Multiple plugins should be able to do output buffering concurrently. For example, page caching plugins rely on output buffering and they work with the AMP plugin that also does output buffering.
Yeah, I didn't mean to make it a dependency. But rather to leverage it if it is installed. Similarly to Embed Optimizer leveraging Optimization Detective if it is installed to prevent lazy-loading LCP embeds, but otherwise continue to lazy-load all embeds using traditional WP filters. |
Feature Description
The Auto Sizes plugin adds
sizes=auto
to all images withloading=lazy
. This is all done server-side without knowledge of which images are actually in the initial viewport across breakpoints. This is knowledge that Optimization Detective has from user visits. In #1077 images which are not in any breakpoint group's initial viewport will be lazy-loaded. However, the addition ofloading=lazy
to these images should also includesizes=auto
. This could be done in the same "Image Loading Optimization" (Image Prioritizer?) dependent plugin of Optimization Detective, or better it could be incorporated as part of the Auto Sizes plugin instead.The text was updated successfully, but these errors were encountered: