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-members/bp-members-blocks.php

    r12750 r12757  
    107107            '<div class="item-header-avatar">
    108108                <a href="%1$s">
    109                     <img src="%2$s" alt="%3$s" class="avatar">
     109                    <img loading="lazy" src="%2$s" alt="%3$s" class="avatar">
    110110                </a>
    111111            </div>',
Note: See TracChangeset for help on using the changeset viewer.