Ad code implementation

About the asynchronous ad code

The asynchronous ad code is a fully asynchronous version of the AdSense ad code that offers improved web latency and a better user experience for your site’s visitors. The advantage of the asynchronous code is that it's guaranteed never to get in the way of other parts of your web page loading. This means that users will be able to load the content of your pages, even if they’re having trouble loading the ads. In particular, mobile users will enjoy less latency when loading web pages.

The key differences between asynchronous and synchronous ad code are:

  • Speed: Asynchronous ad code offers improved web latency, especially on mobile.
  • Improved user experience: Using asynchronous ad code ensures that your users see your content, even if they’re having trouble loading your ads.

For more information, see this Inside AdSense blog post: Faster, more robust web with AdSense.

Implementing the asynchronous ad code

When you generate your AdSense ad code, you have the option to choose between the asynchronous ad code and the existing AdSense ad code. To use the asynchronous code, leave the code type set to "Asynchronous" in the Code type drop-down in the “Ad code” box. Once you’ve generated your asynchronous code, copy and paste the code into your page’s HTML source code, just as you would with the current ad code.

To get the full benefit of the asynchronous code, we recommend that you switch all of the ad units on a given page at the same time.

Syntax for the asynchronous code

The asynchronous ad code has a different syntax to the current AdSense ad code. Here's a side-by-side comparison of the two types of ad code:

Asynchronous ad code Synchronous ad code
<script async src="//
<!-- leaderboard -->
<ins class="adsbygoogle"
(adsbygoogle = window.adsbygoogle || []).push({});
<script type="text/javascript">
    google_ad_client = "ca-pub-xxxxxxxxxxxxxxxx";
    google_ad_slot = "1234567890";
    google_ad_width = 728;
    google_ad_height = 90;
<!-- leaderboard -->
<script type="text/javascript"


We recommend that you thoroughly test all of your pages that use the asynchronous code. If ads are not showing on your site within 48 hours after you've added the asynchronous code, then you should make sure that the ad code is correctly implemented in your site. You can do this by viewing the source of your site from a browser and double checking that the ad code looks exactly like the code that we provided you in your account and includes every line of the ad code. You can also look at your browser's JavaScript error console, where adsbygoogle will display messages about any configuration problems it notices.

For more information about why ads may not display on your website after correctly adding the asynchronous ad code, see content ads are not showing up.

Frequently asked questions

Shouldn’t the asynchronous code have a <script> type attribute?
No. With the asynchronous code we are targeting HTML5, which doesn’t require a "type" attribute. You’re welcome to add type="text/javascript" to the asynchronous code but it won’t change any of the behaviour of the code. Note that with HTML5 (and with all existing web browsers), type="text/javascript" is the default value.
Can I use AdSense asynchronous code and Google Ad Manager asynchronous tags?
No. The asynchronous ad code is not supported by Google Ad Manager.
Can I set the size of the ad directly via CSS?
Yes you can, and doing so allows you to dynamically specify the size of the ad that will be served.
Does the Google Publisher Tag support the asynchronous ad code?
Yes, the asynchronous ad code is supported by the Google Publisher Tag.


Was this article helpful?
How can we improve it?