One of the contributors to
blog loading is adsense ads. Although JS adsense already uses asynchronous to
avoid blocking JS rendering, in reality the loading of AdSense ads is felt when
the blog page is loaded. For that we can use lazyload adsense ads so as not to
add blog loading.
Especially if you install JS
adsense on every ad unit displayed on the blog, then loading the blog will be
added to the loading of some JS adsense. So my advice, just save only 1 JS
adsense above the code </body> for all adsense ad units on the
blog.
But this time I will give
another trick to lazy load adsense ads so as not to add blog loading.
To lazyload on adsense ads,
we can use javascript load on scroll. So simply, JS adsense will not be loaded
before the page is scrolled. Makes sense right?
But to implement this trick,
then we should not place adsense ads in the " above the fold " area or do not place adsense ads in the
display area before the page is scrolled because the ads will not appear.
Now for the lazy trick to
load this adsense ad please replace the JS adsense code with javascript below,
please save above the code </body>
<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'); ad.type = 'text/javascript'; ad.async = true; ad.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; var sc = document.getElementsByTagName('script')[0]; sc.parentNode.insertBefore(ad, sc); })();
lazyadsense = true;
}
}, true)
//]]>
</script>
You can also enter js or other scripts if you want the widget to load after scrolling, for example disqus or other comments . Mayusefull….