[wp-trac] [WordPress Trac] #44427: Introduce lazy-loading API for media and other elements
WordPress Trac
noreply at wordpress.org
Fri Dec 6 15:56:25 UTC 2019
#44427: Introduce lazy-loading API for media and other elements
--------------------------------------+--------------------------
Reporter: mor10 | Owner: flixos90
Type: feature request | Status: assigned
Priority: normal | Milestone: 5.4
Component: Media | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses: performance
--------------------------------------+--------------------------
Comment (by flixos90):
@spacedmonkey
> The reason for the change so that everything uses filters, as it not
only does it make the code much cleaner, but it also gives developers much
more control to unhook this behavior.
You can easily unhook `wp_lazy_load_content_media()` from individual
filters. Also I'd argue "context" from what PHP can give us here is
largely irrelevant - context for lazy-loading media is much more dependent
on browser viewport which is information we don't have here anyway.
I furthermore think introducing generic new filters for something that
simple doesn't make the code cleaner, and it even has a performance
impact: `wp_lazy_load_content_media()` runs a regex that adds `loading`
attributes to all applicable tags in a string. Running it on a single
image tag for example is overkill. Just because we can reuse the function
doesn't mean we should.
Let's take a step back and focus on what we're trying to accomplish here:
The goal is to add support for the `loading` attribute to core. Eventual
improvements and more flexibility can be added on demand in the future as
necessary.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44427#comment:59>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list