Google AdSense is a monetization program executed by Google. This remains the most reliable way for many publishers to earn money...
Google AdSense is a monetization program executed by Google. This remains the most reliable way for many publishers to earn money online. One common problem faced by publishers is that Google AdSense affects the speed of our original blog. Because we have no control to customize resources, we feel unhappy.
Like YouTube video thumbnails, they should use WebP for ad unit images. It is ironic that sometimes they are not bothered to serve with GZIP compression, or do not minimize resources. Massive resources and additional burden of many DNS searches kill the speed of our page like hell.
A few months ago, when I tweeted the speed of the ad unit, I could not find a satisfactory answer. I came back with a solution that would prevent AdSense from slowing down its original content load.
Honestly, personally I am not a big fan of lazy cargo, even for images. But still, I just want to share an option. If you wish, you can try it once, if you are very concerned about the primary content service instead of the ad units.
Instruction for Setup Lazy Loading for AdSense
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- leaderboard -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Technical details :
Basically, what happens when it is loaded asynchronously means that the browser continues to download adsbygoogle.js scripts without blocking the HTML analysis.
Basically, what happens when it is loaded asynchronously means that the browser continues to download adsbygoogle.js scripts without blocking the HTML analysis.
But here, in the slow loading method, I will convert the ASYNC method to the real DEFER. Once the main web page has finished loading, the AdSense script will start downloading into the browser. In this way, the visitor will not have to wait for Adsense to quickly see the entire page.
For this purpose, you do not have to make major changes to your ad unit. We will simply change the loading style of adsbygoogle.js that will do all the magic.
All you need to follow below two Steps
- First of all, remove below script from all ad units.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
- After then, add below JavaScript code in your Theme Footer, possibly just before the </body> tag
<!--noptimize-->
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
<!--/noptimize-->