-
Notifications
You must be signed in to change notification settings - Fork 98
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
Module Proposal: auto-sizes for lazy-loaded images #791
Comments
Thanks @joemcgill, I really like this idea, and I agree the PL plugin would be the perfect avenue to get started on this, given its browser spec is so bleeding edge and still in motion. Do you have any information on browser support? I see the spec is moving, but I'd want to make sure it's supported by at least one major browser before adding it in a plugin. |
I have played sometimes with lazysize.js and found sometimes adding The case in this PR seems only work if we add |
@joemcgill, Thank you for the proposal! I must say, I really like the idea, and I am happy to support you in any way I can. |
Looks like the auto-sizes implementation is moving forward with implementation in Chromium starting. I'm thinking we might want to prioritize some early explorations for supporting this in early 2024 cc: @felixarntz, @adamsilverstein |
The new auto-sizes feature has now landed in Chromium 🎉 I put together a quick demo that can be used for observing how the feature is working in supporting browsers (e.g., Chrome Canary) and existing browsers. ExamplesFor each of the examples, I've use a 960px image with a For each of the following cases, I'm also reporting the Control – the current WP default:
Auto sizes w/ lazy-loading:
Auto sizes w/o lazy-loading:
Auto sizes + fallbacks w/ lazy-loading:
Auto sizes + fallbacks w/o lazy-loading:
Key ConclusionCurrently, it looks like we can apply auto sizes with a fallback (e.g., |
This adds a new module that will automatically enhance the `sizes` attribute of lazy-loaded images to support the new `auto` syntax. See: whatwg/html#4654 Fixes: #791.
This can be considered fixed by #904 and the relevant follow up PRs. Any further development to the plugin can happen against For reference, the plugin is already published here: https://wordpress.org/plugins/auto-sizes/ |
Overview
About the module
Recently, the HTML spec was updated to support sizes="auto" for lazy-loaded images. The purpose of this module would be to automatically add
auto
to the beginning of thesizes
attribute for any image that is being lazy loaded.Purpose
While implementation is still ongoing, this could be a pretty big performance improvement for WordPress sites, since many rely on the default
sizes
attribute rather than filtering the value to a more accurate one based on the intended layout of the site's theme.Scope
This would only implement auto sizes for lazy-loaded images as an experiment until browser adoption for this feature is far enough along to propose for core, and should be a base implementation that a future core proposal would be based on.
This does not take the place of #760, which would still be useful to pursue, but could make that effort less important by getting the same performance benefits for all lazy-loaded images.
At minimum, the implementation should filter
wp_calculate_image_sizes
to prepend "auto, " to the beginning of the string. Given that this is a progressive enhancement, any browser that doesn't recognize the "auto" value in the sizes string, will ignore it and process the rest of the string like normal.It is currently unclear if this syntax is used on an image that is not being lazy loaded, if the original sizes value will be respected or if the default
100vw
fallback for the parser will be used instead, so experimentation against a real implementation will be important. If the default is used, then the filter would need to also check to see if lazy loading is enabled and likely post-filter images to remove auto sizing for any images not being lazy loaded, sincesrcset
andsizes
is calculated prior to lazy loading inwp_filter_content_tags
.Rationale
See above.
Other
Additional info:
The text was updated successfully, but these errors were encountered: