Load Google Ads after entire page has loaded

前端 未结 8 2212
一生所求
一生所求 2020-12-24 09:42

Without Google Ads, my HTTPS webpage loads in about 500ms. With Google Ads, the same webpage takes 2-5 seconds to load. I have two banner ads (one at the top and one at the

8条回答
  •  滥情空心
    2020-12-24 10:47

    This is what I did, after noticing adsense slows down page loading/rendering:

    first of all add this code to your tag:

    
    

    Now, put only one adsense script code, above the tag:

    
    

    Remove adsense from all of your adsense code(one copy at the header is enough).

    Remove all (adsbygoogle = window.adsbygoogle || []).push({}); from your adsense code from your page. We will be using them over our initialize function.

    To our initialize_page() function, add this code:

    function initialize_page()
    {
        (adsbygoogle = window.adsbygoogle || []).push({});//this is for the first adsense
        (adsbygoogle = window.adsbygoogle || []).push({});//this is for the second
        (adsbygoogle = window.adsbygoogle || []).push({});//this is for the third
    }
    

    This code is suitable for 3 adsense on your page. if you use only 2 or 1 adesnes, just remove (adsbygoogle = window.adsbygoogle || []).push({}); from the function respectively.

提交回复
热议问题