[wp-trac] [WordPress Trac] #53675: Omit lazy-loading attribute on first content image/iframe
WordPress Trac
noreply at wordpress.org
Fri Jul 16 19:04:18 UTC 2021
#53675: Omit lazy-loading attribute on first content image/iframe
------------------------------------------+------------------------------
Reporter: flixos90 | Owner: flixos90
Type: enhancement | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 5.5
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses: performance
------------------------------------------+------------------------------
Comment (by flixos90):
@Mte90 A global counter is what I was thinking too. I also agree this
should be filterable - I'd argue in addition to turning it off it would be
useful for themes with specific layouts where more than the first image
typically appears above the fold.
@westonruter This is close to what I did in the prototype plugin used for
the analysis - the one thing missing from yours (as you mention in the
other ticket) was archive support. It would be great if you could review
the prototype plugin (see below) and leave your thoughts.
For reference,
[https://gist.github.com/felixarntz/fcf11eeadaaae695dc35fe2c8eacb446 this
Gist] has the prototype plugin with the logic used during the analysis:
* Increase a counter for every content image (covering featured images and
post content images).
* If the first image is encountered, prevent the `loading="lazy"`
attribute from being added.
* This works for both single post views and archive views - in an archive,
only the first image **from the first post** will not be lazy-loaded.
This plugin uses a function parameter to control how many images to omit
from being lazy-loaded. For the core implementation, we could e.g.
introduce a filter to allow modification. A theme that e.g. displays a
grid archive with 3 columns could then set the number of images to not
lazy-load for archives to 3.
Another thing to note here is that the plugin only focuses on images. The
core implementation should also count iframes in the same way, in a common
counter - i.e. the first image ''or'' iframe won't be lazy-loaded.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53675#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list