Pre-study
It's time to lazy-load offscreen iframes!
An example page with an OpenStreetMap
To ensure the
loads only when the user clicks the button, it is initially hidden using the inline style style="display: none"
.
title
Welcome to HTML Test Content
A simple example for practicing HTML and CSS
About This Page
This page contains various HTML elements to help you test
and practice.
Text formatting
Images and links
Tables and lists
Forms and inputs
Show Map
Enter fullscreen mode
Exit fullscreen mode
However, when inspecting the page, we can see that the contentDocument of the is fully loaded even before any user interaction, as shown in the image below:To prevent unnecessary resource loading before user interaction, add the attribute loading="lazy" to the .
...
...
Enter fullscreen mode
Exit fullscreen mode
When inspecting the page, we notice that the element has an empty contentDocument before the user interacts with it.Additionally, when we check the Network tab, we can see that the resources for the are not loaded before the user clicks the button.After clicking the button, the resources for the are successfully loaded:Feel free to follow me on GitHub 🎉
To ensure the
style="display: none"
.title
Welcome to HTML Test Content
A simple example for practicing HTML and CSS
About This Page
This page contains various HTML elements to help you test
and practice.
Text formatting
Images and links
Tables and lists
Forms and inputs
Show Map
Enter fullscreen mode
Exit fullscreen mode
However, when inspecting the page, we can see that the contentDocument of the is fully loaded even before any user interaction, as shown in the image below:To prevent unnecessary resource loading before user interaction, add the attribute loading="lazy" to the .
...
...
Enter fullscreen mode
Exit fullscreen mode
When inspecting the page, we notice that the element has an empty contentDocument before the user interacts with it.Additionally, when we check the Network tab, we can see that the resources for the are not loaded before the user clicks the button.After clicking the button, the resources for the are successfully loaded:Feel free to follow me on GitHub 🎉