Load Adsense Async Script Only Once to Speed Site

If you use the new Google Adsense Asynchronous script, you can load Adsense script only once even though you might be using multiple different ad units for your pages. Loading the same script repeatedly does not add any benefit, slows page speed,  and this has been confirmed by Google.

Michael Kleber of the Google Ads Latency Team posted code details of the new asynchronous ad code script and says

A script, which only needs to appear once on your page, even if you have multiple ads. It is loaded asynchronously, so it is safe and most efficient to put it near the top.

I also confirmed the same with him on Google+. But note no such announcement has been made by the Adsense team and you might want to verify with them.

confirm Adsense code change

Load Adsense Async Script Once

This means you can load the script only once for all your ad units. A typical ad unit with asynchronous code looks like this –

<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
(adsbygoogle = window.adsbygoogle || []).push({});

The first line is the Adsense javascript which loads the ads. The ads will not display without loading this script with the Adsense code.

Now you can load the adsbygoogle.js script only once. So if you have 3 Adsense ad units you can move the first line of the Adsense code higher up in your HTML code and use it once only.

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

This will ensure that the ad code starts loading faster and ad displays faster. The asynchronous code ensures it does not block loading the rest of your site.

NOTE: Please do confirm with Google Adsense team before you start changing your code. While editing Adsense code is against terms of service, in special cases Adsense does allow code modification like that for A/B testing to find the higher paying ads, or for responsive Adsense codes to fit responsive site designs.

Share with friends

About the Author: P Chandra is editor of QOT, one of India's earliest tech bloggers since 2004. A tech enthusiast with expertise in coding, WordPress, web tools, SEO and DIY hacks.