Error - Asynchronous adsense code in HTML

14,918

Solution 1

Use this code instead on any of them... I'm currently using this...Try it

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

Solution 2

You're writing an XHTML document (either because of the Content-Type or an XML declaration).

Therefore, the entire document must be valid XML.

Unlike regular HTML, all XML attributes must have values.

Solution 3

I have a solution for the same problem with Hubspot Tracking Code with Blogger.

When adding the following code to the theme HTML in Blogspot, I get an error.

Error parsing XML, line 2490, column 62: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.

<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/xxxxxx.js"></script>
<!-- End of HubSpot Embed Code -->

I fixed it be using the above fix changing async defer to async="async defer"

<!-- Start of HubSpot Embed Code 17/03/2017-->
<script type="text/javascript" id="hs-script-loader" async="async defer" src="//js.hs-scripts.com/2336222.js"></script>
<!-- End of HubSpot Embed Code -->
Share:
14,918
Aws Ahmed
Author by

Aws Ahmed

Updated on June 15, 2022

Comments

  • Aws Ahmed
    Aws Ahmed almost 2 years

    I'm a blogger and I monetize my blog with adsense. While coding or in fact adding asynchronous code inside <head></head>tag of my blog it appears that I have to add it like this:

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

    instead of like this:

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

    Otherwise it will show me an error. Can anyone explain why? Do you know if I'm allowed to add this (according to adsense)?

  • Benjamin Gruenbaum
    Benjamin Gruenbaum about 10 years
    Does it have any implications on the google adsense TOS?
  • SLaks
    SLaks about 10 years
    @BenjaminGruenbaum: Google does not care whether your page is XHTML or tag soup
  • Benjamin Gruenbaum
    Benjamin Gruenbaum about 10 years
    Is async a valid attribute on a script tag in xhtml? ref: w3.org/MarkUp/DTD/xhtml-script-1.mod
  • Heretic Monkey
    Heretic Monkey about 7 years
    Note that the async attribute and the defer attribute are separate attributes in HTML. You should change it to async="async" defer="defer".