How do you Defer Parsing of JavaScript for YouTube video on a WordPress site?

后端 未结 3 2452
轮回少年
轮回少年 2021-02-19 18:43

I just today realized that of my 1.2 MB site (per GTMetrix), 550k of it is a YouTube video.

My web site is a WordPress site, and the current video loads in an iframe.

3条回答
  •  旧巷少年郎
    2021-02-19 19:14

    You can achieve this with two simple steps......

    1. Update your embed code like flowing....
    
    
    1. Here is the java script part....
    function init() { 
    var vidDefer = document.getElementsByTagName('iframe');
    for (var i=0; i

    Reference For more details:

    https://scottdeluzio.com/defer-parsing-javascript-youtube-videos/

    https://varvy.com/pagespeed/defer-videos.html

    P.S. I am personally using this and it works.

    Thanks Sabbir H

提交回复
热议问题