

Lazy-loading this iframe avoids having to load all of the script necessary for the embed. Instagram embeds provide a block of markup and a script, which injects an iframe into your page. Lazy-loading Instagram embeds (saves >100KB gzipped on initial load): If you are looking for more efficient ways to load YouTube embeds, you may be interested in the YouTube lite component. I have opened an internal bug with YouTube to discuss adding loading=lazy to its embed code.

Lazy-loading YouTube video embeds (saves ~500KB on initial page load): Īnecdote: when we switched to lazy-loading YouTube embeds for, we saved 10 seconds off of how soon our pages could be interactive on mobile devices. What if we could change the web at large so that lazy-loading offscreen iframes was the default? It would look a little like this: What impact might we see from lazy-loading popular iframe embeds? # Chrome shows a placeholder for lazy-loaded iframes that are still being fetched. iframes that aren't hidden will only load when they're within the load-in distance threshold. If an iframe meets any of these conditions, Chrome considers it hidden and won't lazy-load it in most cases.

The loading attribute affects iframes differently than images, depending on whether the iframe is hidden. appendChild (iframe ) iframe-specific lazy-loading behavior # If you need to dynamically create iframes via JavaScript, setting iframe.loading = 'lazy' on the element is also supported: var iframe = document. Not specifying the attribute at all will have the same impact as explicitly eagerly loading the resource, except for Lite Mode users, where Chrome will use the auto value to decide whether it should be lazy-loaded. Using the loading attribute on iframes works as follows:

Third-party embeds cover a wide range of use cases, from video players, to social media posts, to ads. This demo of shows lazy-loading video embeds: Why should we lazy-load iframes? # This saves data, speeds up the loading of other parts of the page, and reduces memory usage. Standardized lazy-loading of iframes defers offscreen iframes from being loaded until the user scrolls near them. We are happy to share that browser-level lazy-loading for iframes is now standardized and is also supported in Chrome and Chromium-based browsers. Standardized lazy-loading for images landed in Chrome 76 via the loading attribute and later came to Firefox.
