[wp-trac] [WordPress Trac] #58773: Lazy Load oEmbed iframes

WordPress Trac noreply at wordpress.org
Mon Jul 10 20:09:21 UTC 2023


#58773: Lazy Load oEmbed iframes
-----------------------------+-----------------------------
 Reporter:  adamsilverstein  |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  General          |    Version:
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 == Why lazy load oEmbed iframes?
 * Lazy loading prevents wasted resources from loading if the user never
 scrolls down to view the oEmbed
 * Iframe lazy loading is handled directly by the browser, making the
 change simple (add a single attriute) and ensuring users get a great
 experience


 ==  Lazy loaded oEmbeds history
 WordPress has [https://make.wordpress.org/core/2021/02/19/lazy-loading-
 iframes-in-5-7/ lazy loaded iframes] since version 5.7 and the original
 proposal included lazy loading for oEmbed iframes (as long as the provider
 also included width and height attributes).

 Ultimately, dynamic addition of lazy loading of oEmbeds was removed from
 core because it was found to create issues, especially with embeds of
 other WordPress posts.

 == Proposed Solution
 This ticket proposes new approach relies on altering the cached iframe
 instance we store for each oEmbed. In particular:
 * When the oEmbed iframe HTML is retrieved, if it doesn't already contain
 a `loading` attribute, it is run through `wp_iframe_tag_add_loading_attr`
 to add the lazy loading iframe under the correct conditions
   * Will not add lazy loading to WordPress iframes because of the `data-
 secret` check
   * Only adds lazy loading to iframes with the height and width present.
   * Runs before the `oembed_result` filter, so developers can remove the
 attribute if desired.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58773>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list