Load Google Ads after entire page has loaded

前端 未结 8 2078
一生所求
一生所求 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:45

    Place the code for initiating the ad's at the bottom of the page just before the closing /body> tag

    0 讨论(0)
  • 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 <Body> tag:

    <body onLoad="initialize_page();">
    

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

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    

    Remove adsense <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 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.

    0 讨论(0)
提交回复
热议问题