[wp-trac] [WordPress Trac] #44427: Introduce lazy-loading API for media and other elements
WordPress Trac
noreply at wordpress.org
Fri Dec 13 20:20:42 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 spacedmonkey):
Reviewing
[https://core.trac.wordpress.org/attachment/ticket/44427/44427.7.diff
44427.7.diff]
- Agree iframes should be removed, as they are problematic.
{{{#!php
foreach ( array( 'the_content', 'the_excerpt', 'comment_text',
'widget_text_content' ) as $filter ) {
add_filter( $filter, 'wp_lazy_load_content_media' );
}
}}}
- These lines above. I think the priority should be changed to 8. This
means it fire way before most plugins. It also means that added before
blocks and shortcodes are added. This stops any image tags that are added
in via a third party block/shortcode from getting the lazy loading
attribute. There maybe good reason a develop might want a image to not
lazy loading, like if they are using a tracking pixel in a shortcode (I
have done myself so I know that happens).
- Should we disable lazy loading image if the theme has not
defined add_theme_support for
[https://developer.wordpress.org/reference/functions/add_theme_support/#html5
html5]? This would stop older theme written in XHTML from becoming invalid
markup. A simple workout like this might work.
{{{#!php
add_action( 'template_redirect', 'wp_remove_lazy_tags', 5 );
function wp_remove_lazy_tags(){
if( false === get_theme_support( 'html5' ) ) {
add_filter( 'wp_lazy_load_content_media', '__return_empty_array');
}
}
}}}
- I think we need more unit tests, especially ones with malforms img tags,
like attributes on new lines, data attributes and the like.
Generally I think we are nearly there.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44427#comment:64>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list