Lazy Load IFRAMEs
We've known for a decade that lazy loading resources like JavaScript, CSS, and especially images is a massive performance win for web pages. At first we used tricks and JavaScript to do the lazy loading, but more recently native image lazy loading has debuted in browsers.
Did you know that you can also lazy load IFRAMEs using the same loading="lazy"
attribute and value?
<iframe
src="https://davidwalsh.name/"
loading="lazy"
onload="alert('Loaded!');"
/>
You can see how lazy loading IFRAMEs works with this demo:
This single attribute to perform a complex but useful operation is the ideal solution for lazy loading just about anything. I'm so thankful that browsers are implementing APIs that make using best practices so easy!
Introduction
For quite a long time now websites with the so called "parallax" effect have been really popular.
In case you have not heard of this effect, it basically includes different layers of images that are moving in different directions or with different speed. This leads to a...
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API.
I was inspired when I first saw Addy Osmani's original ShineTime blog post. The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
Modern browsers are nice in that they allow you to style some odd properties. Heck, one of the most popular posts on this blog is HTML5 Placeholder Styling with CSS, a tiny but useful task. Did you know you can also restyle the textarea resizer in WebKit...
This browser feature looks really like a huge gamechanger. Would love so much to use it with profit although it doesn’t seem to work correctly for me.
[First of all, using it with images instead of iframes always worked perfectly, so all this regards only loading=”lazy” for iframes.]
After hours of testing on different pages, what I see is that using loading=”lazy”, Iframes load WAY TOO EARLY.
This apparently buggy behavior happens only if the page itself is NOT loaded from another iframe. So this rules out CodePen as a viable tool to show this.
Let’s make a text.html file from this code, almost identical to your example, to highlight exactly what I’m saying:
https://gist.github.com/jeff-at-livecanvas/bb1a803465419c62d623305daf6722cd
Opening this file in a Chrome window, with an internal height of 700 pixels, shows the Loaded! message immediately.
Same happens with latest Firefox too.
Would be great if somebody could shed some light on this.