Embedding and web termsUpdated
Lazy loading
Also called: loading="lazy", lazy load iframes, deferred loading
Definition
Lazy loading means the browser waits to load an image or iframe until the visitor scrolls near it, instead of fetching everything as the page opens. In HTML you turn it on by adding loading="lazy" to <img> and <iframe> elements.
How native lazy loading works
The loading attribute takes eager, the default, or lazy. With lazy, the browser decides how close to the viewport an element must be before fetching it, and that distance varies between browsers. Major browsers support it on iframes as well as images. Before the attribute existed, sites did the same job with JavaScript that watched the scroll position.
Lazy loading changes when something downloads, not how much. Once a visitor scrolls down, the full embed still loads, so showing fewer items is what reduces the total.
When not to lazy load
- Images or frames visible as soon as the page opens. web.dev advises against lazy loading anything likely to be in the first viewport, especially the largest image, because it can arrive later than it would have.
- Tiny elements where the saving doesn't matter.
- Images without width and height, unless you add them; otherwise late arrivals push content around.
Lazy loading and embeds
Third-party embeds below the fold are the best candidates. web.dev's examples include video and social embeds that each pull in roughly 100 to 500 kilobytes, none of which a visitor needs until they scroll that far.
Both LinkedInEmbed snippets load the widget lazily: the iframe snippet includes loading="lazy", and the script sets it on the frame it creates. A widget placed at the very top of a page loads straight away anyway, since it's already in view. Wherever it sits, give the area a sensible height so the page doesn't jump when it fills in; see Cumulative Layout Shift. On a page with several embeds, lazy loading also stops them all competing for bandwidth at once.
Sources
Related terms
- iframe
- An iframe (inline frame) is an HTML element, <iframe>, that displays a separate web page inside the current one. The embedded page loads from its own address and runs as its own document, kept apart from the host page's styles and scripts.
- Core Web Vitals
- Core Web Vitals are three metrics that describe a page's real-world user experience: Largest Contentful Paint for loading, Interaction to Next Paint for responsiveness and Cumulative Layout Shift for visual stability. Each has a published “good” threshold.
- Cumulative Layout Shift (CLS)
- Cumulative Layout Shift (CLS) is a Core Web Vitals metric for visual stability: it measures how much visible content moves unexpectedly while a page is open. web.dev rates a score of 0.1 or less as good and anything above 0.25 as poor.
- Script tag (async and defer)
- A script tag, <script>, adds JavaScript to a web page. By default an external script pauses HTML parsing while it downloads and runs; the async and defer attributes let the browser keep parsing and run the script later.
Show your LinkedIn on your website
Paste a LinkedIn URL and embed it with one snippet. Free plan, no credit card.
Put your LinkedIn on your website today
Create your first widget in about two minutes. Free plan, no credit card required.