Menu

Your Google Maps and YouTube embeds are slowing your homepage. Load them on click instead
📰

Your Google Maps and YouTube embeds are slowing your homepage. Load them on click instead

DEV Community: html·Rahil Khan·3 days ago
#iIcXHfJb
#devto2#devto#dev#embed#iframe
Reading 0:00
15s threshold

A lot of small-business homepages embed a Google Map in the footer and a YouTube video in the middle. Each embed is an iframe that pulls in its own scripts, fonts and images, often more than the rest of the page combined, and it loads even for visitors who never scroll that far.

Two easy fixes, from least to most effort:

1. Lazy-load the iframe

Browsers support native lazy loading on iframes. Add one attribute and the embed waits until the visitor scrolls near it:

<iframe src= "https://www.google.com/maps/embed?pb=..." width= "600" height= "400" loading= "lazy" title= "Map to our shop" style= "border:0" ></iframe>

Enter fullscreen mode

Exit fullscreen mode

Keep the width / height so the layout doesn't jump when it loads, and add a title for screen readers.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.