--- url: "https://web.dev/articles/iframe-lazy-loading" titulek: "It's time to lazy-load offscreen iframes! | Articles | web.dev" h1: "It's time to lazy-load offscreen iframes! Stay organized with collections Save and categorize content based on your preferences." popis: "This post covers the loading attribute and how to use it to control the loading of iframes." jazyk: "en" kanonicka: "https://web.dev/articles/iframe-lazy-loading" drobecky: ["Articles", "It's time to lazy-load offscreen iframes!"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:55:19" znaku: 7344 slov: 1019 kodovani: "iso-8859-2" sha256: "d3ec299885c07000e73c629eb4172c5c4944850d4f9fce35071cffb12f92a164" --- It's time to lazy-load offscreen iframes! Stay organized with collections Save and categorize content based on your preferences. Addy Osmani Barry Pollard Browser Support 77 79 121 16.4 Lazy-loading of `` This [demo](https://lazy-load.netlify.app/iframes/) of ` ` Not specifying the attribute has the same impact as explicitly eagerly loading the resource. If you need to *dynamically* create iframes using JavaScript, setting `iframe.loading = 'lazy'` on the element is also [supported](https://bugs.chromium.org/p/chromium/issues/detail?id=993273): `var iframe = document.createElement('iframe'); iframe.src = 'https://example.com'; iframe.loading = 'lazy'; document.body.appendChild(iframe);` How does lazy-loading popular iframe embeds impact the user experience? Making lazy-loading iframes the default would make websites much more responsive. The following examples show Time to Interactive (TTI) improvements and data savings for media embeds, but lazy-loading advertising iframes can give similar benefits. YouTube Lazy-loading YouTube video embeds saves around 500KB on initial page load: `` Chrome.com reduced its TTI by 10 seconds by lazy-loading offscreen YouTube embeds. Instagram Instagram embeds provide a block of markup and a script that injects an iframe into your page. Lazy-loading this iframe avoids having to load all the script the embed needs, and can save about 100 kB on initial load. Because these embeds are often displayed below the viewport in most articles, this is a reasonable candidate for iframe lazy-loading. Spotify Lazy-loading Spotify embeds can save 514 KB on initial load. `` Facebook's social plugins Facebook *social plugins* let developers embed Facebook content in their web pages. The most popular of these is the [Like plugin](https://developers.facebook.com/docs/plugins/like-button/), a button that shows how many users have "liked" the page. By default, embedding the Like plugin in a web page using the Facebook JSSDK pulls in around 215 KB of resources, 197 KB of which is JavaScript. The plugin often appears at the end of an article or near the end of a page, so loading it eagerly when it's offscreen can be suboptimal. Facebook's Like plugin. Thanks to engineer Stoyan Stefanov, [all of Facebook's social plugins now support standardized iframe lazy-loading](https://developers.facebook.com/docs/plugins/like-button#settings). Developers who opt into lazy-loading through the plugins' `data-lazy` configuration can now prevent these plugins loading until the user scrolls nearby. This lets the embed keep functioning for users that need it, while saving data for users who don't scroll all the way down a page. We are hopeful this is the first of many embeds to explore standardized iframe lazy-loading in production. When you want more control over iframe lazy-loading Browser-level iframe lazy loading is [well supported across all the major browsers](https://caniuse.com/loading-lazy-attr) and is recommended for most use cases, to remove the need for extra dependencies on JavaScript. However, if you have a need to support older browsers or want to have more control over lazy-loading thresholds then you can use a third-party library to lazy-load iframes on your site. The [lazysizes](https://github.com/aFarkas/lazysizes) JavaScript library is one such library that allows additional options should you need it. Are there exceptions to offscreen iframe lazy loading? An early experiment with automatically lazy-loading iframes for Data Saver users in Chrome had an exception for hidden iframes, often used for communications or analytics. These were prevented from loading lazily, and always loaded to prevent breaking those features. The `loading` attribute doesn't apply these heuristics, so the developer always gets to choose what gets lazy-loaded. The `loading` attribute should always be honored, subject to distance limits and other browser choices (such as printing). Resources For more lazy-loading ideas, see web.dev's [image and video lazy-loading collection](/explore/fast#lazy-load-images-and-video). *With thanks to Dom Farolino, Scott Little, Houssein Djirdeh, Simon Pieters, Kayce Basques, Joe Medley, and Stoyan Stefanov for their reviews.* Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2024-09-23 UTC.