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-messages/bp-messages-filters.php

    r12745 r12757  
    7878add_filter( 'bp_get_message_thread_content',          'stripslashes_deep', 1 );
    7979
     80add_filter( 'bp_get_the_thread_message_content', 'bp_core_add_loading_lazy_attribute' );
     81
    8082// Personal data export.
    8183add_filter( 'wp_privacy_personal_data_exporters', 'bp_messages_register_personal_data_exporter' );
Note: See TracChangeset for help on using the changeset viewer.