How to install lazyload adsense with auto ads

 

How to install lazyload adsense with auto ads



A blogger is certainly no stranger to adsanse, adsanse is an alternative way for a publisher to make money on a blog, on the other hand adsanse js also affects the loading of the blog so it's heavy.

For those of you who have just received Adsense and have implemented the script provided by Adsense, of course you will be surprised when you check your blog's speed decreases by 40%.

therefore on this occasion I will give tips on how to install the correct ad unit and use lazyload adsense to speed up blog loading.

What is Lazyload Adsense?

lazyload adsanse is a technique to delay the loading of adsanse js on the website to be asynchronous, meaning that once the top content is fully loaded, the adsanse js will not load.

lazyload adsense is useful for speeding up blog loading by temporarily delaying the loading of adsense js. and furthermore the adsense js will be loaded when the page is scrolled by the user.

How to Install Lazyload Adsense

please copy the code below and place it above the </body> code if you don't find it it may have been parsed so that it becomes <!--</body>--></body> and change the part that I have marked with your ca-pub code and click save

<script>
    //<![CDATA[
    var lazyadsense = false; window.addEventListener("scroll", function(){ if ((document.documentElement.scrollTop != 0 && lazyadsense === false) || (document.body.scrollTop != 0 && lazyadsense === false)) { (function() { var ad = document.createElement('script'); var crs = document.createAttribute('crossorigin'); crs.value = 'anonymous'; ad.setAttributeNode(crs);  ad.async = true; ad.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-880246522xxxxxxx'; var sc = document.getElementsByTagName('head')[0]; sc.parentNode.insertBefore(ad, sc); })(); lazyadsense = true; } }, true)
    //]]>
    </script>

if your template still has this script
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-880246522xxxxxxx" crossorigin="anonymous"></script> please removed.

Recommended Adsense Ad Unit Writing

one of the causes of slow loading blogs is due to the repeated writing of the adsense script (adsbygoogle.js). so every time you add an ad unit you don't need to rewrite the adsense script, write the correct ad unit like the example below


    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="ca-pub-880246522xxxxxxx"
         data-ad-slot="69271xxxxx"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    <script>
         (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

Writing Adsense Ad Units Not Recommended


    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-880246522xxxxxxx" crossorigin="anonymous"></script>
    <!-- link -->
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="ca-pub-880246522xxxxxxx"
         data-ad-slot="69271xxxxx"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    <script>
         (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

so many ways to install lazyload adsense with auto ads hopefully it's useful



Post a Comment

Previous Post Next Post
Marwat Tech

let's build a community