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. Mobile users in particularly will enjoy less latency when loading web pages.

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.

View example of the asynchronous ad code

    <script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
        style="display:inline-block;width:300px;height:250px"
        data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
        data-ad-slot="6440411535"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

Troubleshooting

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, 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 we provide 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 behavior 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 DFP asynchronous tags?

No. The asynchronous ad code is not supported by DFP.

Can I set the size of the ad directly via CSS?

Yes you can, 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.