#50756 closed enhancement (fixed)
Lazy-load iframes
Reported by: | flixos90 | Owned by: | flixos90 |
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch has-unit-tests has-dev-note |
Focuses: | Cc: |
Description
As part of #44427, it was considered to lazy-load iframes in addition to images, however at that point the loading
attribute on iframe
tags was not yet formalized as part of the living HTML standard. This has changed a few weeks ago (see the iframe loading attribute), so we should consider adding a loading="lazy"
attribute to iframes as well.
Likely the biggest surface area here will be oEmbed content, which is probably the most common way that WordPress sites include iframes.
We should generally try to follow a similar implementation like we did for images, relying on wp_lazy_loading_enabled()
and wp_filter_content_tags()
, which were intentionally built and named in a way that they are not limited to images only.
Another principle that we should follow is that the attribute should only be added to iframes which have width
and height
attributes specified.
This web.dev post provides more information on iframe lazy-loading.
Change History (10)
This ticket was mentioned in PR #703 on WordPress/wordpress-develop by felixarntz.
4 years ago
#1
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
#2
@
4 years ago
- Keywords needs-dev-note added
- Milestone changed from Future Release to 5.7
With https://github.com/WordPress/wordpress-develop/pull/703 I've taken a first pass on a PR for this, including tests.
The main use-case for iframes in WordPress content today is oEmbed, which automatically transforms e.g. URLs. Since that filter runs (with priority 8) before wp_filter_content_tags()
(priority 10) on the_content
, no extra thinking was necessary to support those, it just works by adding iframe
support to wp_filter_content_tags()
.
Note that not all oEmbed providers produce server-side iframe
output. Furthermore, note that not all oEmbed iframe
output contains width
and height
attributes which, like for images, are necessary to add a loading
attribute in order to avoid content shifting.
cc @azaozz
#4
@
4 years ago
@westonruter @azaozz I've addressed the code review feedback on the PR and refreshed against latest trunk
. After some performance testing, it looks like the current patch is good to go.
This ticket was mentioned in Slack in #core by flixos90. View the logs.
4 years ago
felixarntz commented on PR #703:
4 years ago
#7
Addressed the remaining feedback here.
hellofromtonya commented on PR #703:
4 years ago
#9
Trac ticket closed with changeset https://core.trac.wordpress.org/changeset/49808
#10
@
4 years ago
- Keywords has-dev-note added; needs-dev-note removed
Dev note published: https://make.wordpress.org/core/2021/02/19/lazy-loading-iframes-in-5-7/
wp_filter_content_tags()
(which was specifically made to support different tags) to also scan foriframe
tags in the content.wp_filter_content_tags()
logic to iterate through foundimg
andiframe
tags separately, making necessary modifications.wp_iframe_tag_add_loading_attr()
, and a filter of the same name, similar towp_img_tag_add_loading_attr()
.wp_lazy_loading_enabled()
to returntrue
by default foriframe
tags.Trac ticket: https://core.trac.wordpress.org/ticket/50756