For those of you who use their blog as a source of income, you must be familiar with Google AdSense. Yes, Google AdSense is a Google product which is one of the reasons and attractions for publishers to further develop their sites. Although not all of them have the same reason.
On the other hand, AdSense is one of the publishers of loading because the ads displayed by JS AdSense will reduce the loading speed of our blog even though JS AdSense is already using asynchronous, but it will still make the blog wait longer to load.
Here I will give an example of a comparison image before and after using this Lazy Load AdSense trick.
Well, for those of you who want to speed up the loading of their blog, please follow these tips.
How to Speed up Blog Loading with Lazy Load AdSense?
The workings of this code are quite simple, namely, ads will appear after we scroll the page. So AdSense JS will not appear before we scroll the site page.
These tips are intended for friends who have installed AdSense on their blogs. For those who haven't, the code that I will share can be used for other needs, such as loading external JS links.
First Open Blogger > then Click the Theme menu >next Click the Edit HTML button > Add the code below before </body>or<!--</body>--></body> tag
<script type='text/javascript'>
//<![CDATA[
// Lazy Load AdSense
var lazyadsense=!1;window.addEventListener("scroll",function(){(0!=document.documentElement.scrollTop&&!1===lazyadsense||0!=document.body.scrollTop&&!1===lazyadsense)&&(!function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a)}(),lazyadsense=!0)},!0);
//]]>
</script>
If not, make sure to remove all AdSense JS links that are usually embedded in the AdSense ad unit code. Like this :
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
This code can also be combined with the JS Adblock Killer link that I shared in the post "How to Install the Latest Version of Adblock Killer". For those of you who have done the trick, you can use this code:
<script type='text/javascript'>
//<![CDATA[
// Lazy Load AdSense
var lazyadsense=!1;window.addEventListener("scroll",function(){(0!=document.documentElement.scrollTop&&!1===lazyadsense||0!=document.body.scrollTop&&!1===lazyadsense)&&(!function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src="https://cdn.jsdelivr.net/gh/Arlina-Design/quasar@master/arlinablock.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a)}(),lazyadsense=!0)},!0);
//]]>
</script>