Hi, I have a YouTube embeded video on some of my product pages and it increased my page load time by 4-7 seconds. I know that I can add the media through Shopify instead, but I do not want to go that route and I read that it doesn’t help much.
So, does anyone know how to have my YouTube embeds load after everything else? Or at least speed up the page load time while keeping the video?
B) The best way, but a little more effort is to create a static image with a play button and load that, then set a JavaScript listener for click on the image and when that gets clicked, replace the image with the embedded video. I don’t have a tutorial for this one but just send that explanation to your developer, they should be able to figure it out. If you get stuck we have a service called Deferred Video Loading to solve that: https://speedboostr.com/services.
If editing yourself, remember to duplicate your live theme first and work off the new backup theme while you’re editing, so any changes don’t affect the live site + you can measure the before / after to verify you’ve done it correctly and gained speed.
I found a solution/work-around to lazy load the embeds on most popular browsers (Google Chrome, Firefox and soon to be Safari) without needed to add any JavaScript.
Just add loading=“lazy” after <iframe and it works without any other coding needed.
Example:
This also works for images by putting loading=“lazy” after <img.
I found an even better solution than just lazy loading. It is called the Facade Method and it SIGNIFICANTLY improves page load time, while still allowing for the YouTube embed.