Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/16/2020 06:02:01 AM (4 years ago)
Author:
r-a-y
Message:

Add lazy loading support for images and iframes.

In order to take advantage of native browser support for lazy loading,
this commit adds the 'loading="lazy"' attribute to all <img> and
<iframe> elements used throughout BuddyPress (activity content,
private messaging content and avatar display).

The generic function, bp_core_add_loading_lazy_attribute(), is
introduced to help with this.

A special case is made for WordPress post embeds. As of this commit,
only Chromium-based browsers (77+) support iframe lazy loading if the
iframe is visible on load. (See https://web.dev/iframe-lazy-loading/#iframe-specific-lazy-loading-behavior.)
Since WordPress post embeds uses inline CSS to hide their iframe on
initial load, we need to remove their inline CSS so lazy loading can
be properly applied.

Props r-a-y, imath.

Fixes #8340.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-filters.php

    r12756 r12757  
    9191add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
    9292add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
     93
     94add_filter( 'bp_get_activity_content_body', 'bp_core_add_loading_lazy_attribute' );
     95add_filter( 'bp_activity_comment_content',  'bp_core_add_loading_lazy_attribute' );
    9396
    9497add_filter( 'pre_comment_content',                   'bp_activity_at_name_filter' );
Note: See TracChangeset for help on using the changeset viewer.