How can you lazy-load videos and third-party embeds?

ProcrustesPR

Whether to lazy-load depends on the embedding method and purpose. For iframes below the fold that do not need to appear immediately, you can use loading=”lazy”. For resource-heavy third-party players or chat tools that only some visitors will use, you can show a placeholder first and load the embed after user interaction. For native video elements, manage downloads of the video, poster, and metadata separately. If a video needs to be discoverable by Google Search, do not wait for a click or scroll to insert it; performance improvements must also account for search requirements.

ProcrustesPRProcrustesPRHow should I divide my DIY SEO budget?

Defer below-the-fold iframes along with their subresources

Third-party players may load additional resources such as JavaScript as well as the video itself. An iframe is another HTML document embedded within the page. Its subresources may compete with the main page for bandwidth, and processing this content may also affect responsiveness.

  • loading=”lazy”: defers the iframe’s HTML and subresources until the iframe approaches the viewport, without waiting for it to be fully visible.
  • loading=”eager”: the default behavior, which loads immediately and does not defer downloads.
  • Set width and height and use styling to reserve space, reducing layout shifts during loading.

Start by assessing videos or social posts below an article. If readers have not yet reached them and they do not need to load in advance, they are good candidates for lazy loading. Avoid deferring every embed indiscriminately.

Use placeholders for embeds that visitors may not use

A facade shows an image or suitable HTML content in place of the actual embed, then loads the embed after user interaction. For example, a video can display a static preview image first and load the player iframe only after a click. A chat tool can initially show an entry point and load the actual functionality when the user needs it.

This suits embeds that are costly to download but may go unused. Visitors who do not play the video need not download the resources required by its player. However, if there is a legitimate need for autoplay, a click-to-load approach cannot simply be applied.

Manage native video, poster, and metadata downloads separately

For a video element, you can set a poster and use preload=”none” or preload=”metadata” to avoid downloading video content by default. With preload=”metadata”, metadata may still be downloaded, so requests are not eliminated entirely. The newer loading=”lazy” can also defer poster and metadata downloads until the video approaches the viewport, in environments that support it.

If the target environment does not support the required native lazy-loading behavior, consider a JavaScript solution. If the poster is the Largest Contentful Paint (LCP) element, assess separately whether to prioritize its loading rather than deferring it simply because it belongs to a video.

For video search visibility, do not wait solely for user interaction

Google’s video SEO documentation requires using common video containers, such as video, iframe, embed, or object, and advises against relying on user actions or URL fragments to load videos. If you insert a video using JavaScript, use the URL Inspection tool to confirm that it appears in the rendered HTML. A facade that inserts a player only after a click can improve initial loading performance, but it is not automatically a universal solution that meets video search requirements.

ProcrustesPRProcrustesPRWhy can I not find my published article on Google?

Lazy-loading videos and third-party embeds: perspectives from across the web

Should video posters always be lazy-loaded?

Not necessarily. If the poster is the page's Largest Contentful Paint (LCP) element, consider using an image preload hint and a higher fetch priority to load it earlier. Conversely, if the video is not the largest element in the viewport, preloading its poster may compete with other critical resources for bandwidth and delay LCP instead. Base the approach on the page's actual content.

What else should you check if Google needs to discover the video?

First, check whether the video loads only after user interaction or through a URL fragment. Avoid both approaches: video loading should not depend solely on user interaction, and Google Search generally does not support URL fragments. If you insert the video using JavaScript, use the URL Inspection tool to confirm that it appears in the rendered HTML. You can also provide structured data, a video sitemap, or Open Graph metadata to help Google discover the video.

What can you do when native lazy loading is not suitable?

Consider a JavaScript solution. This may be useful when target browsers do not support the loading attribute needed for videos, or when you need to lazy-load resources such as CSS background images. The example in the reference waits until the video enters the viewport before changing the data-src attributes on its child source elements to src. Only then are video requests made. If search engines need to discover the video, you must still account for their video loading requirements.

Is lazy loading the only way to improve third-party code performance?

No. Third-party scripts can add functionality, but they can also consume bandwidth and computing resources. If they cause problems, first check whether any unnecessary scripts can be removed, then evaluate deferring loading until the page's main content is interactive, using lazy loading, or optimizing script delivery. The choice should still account for whether the functionality needs to be available immediately.

ProcrustesPREight SEO essentials for beginners: Website speed

References

  1. Video performanceweb.dev — Discusses: Should video posters always be lazy-loaded?
  2. 影片搜尋引擎最佳化 (SEO) 最佳做法 | Google 搜尋中心  |  Documentation  |  Google for Developersdevelopers.google.com — Discusses: What else should you check if Google needs to discover the video?; What can you do when native lazy loading is not suitable?
  3. Lazy load images and <iframe> elementsweb.dev — Discusses: What can you do when native lazy loading is not suitable?
  4. What Is Interaction to Next Paint? INP vs. FID Explainedwww.semrush.com · 2024-05-29T08:58:00Z — Discusses: Is lazy loading the only way to improve third-party code performance?

Related articles

How should I divide my DIY SEO budget?Why can I not find my published article on Google?Eight SEO essentials for beginners: Website speedEight SEO essentials for beginners: Getting your pages indexedEight SEO essentials for beginners: Page titles and descriptionsThe Five Most Common Mistakes SEO Beginners MakeHow to Set Up Heading Tags for SEO: Define Topics and Hierarchy Before Adding KeywordsWhat are the benefits and development challenges of SPAs?
ProcrustesPR
ProcrustesPR