Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 34
    I'm not sure you even need async="true", you can just write 'async'
    – vsync
    Commented May 4, 2010 at 14:36
  • 4
    so if i generate the script tag like google does it - what would be correct: var s = document.createElement('script'); s.async='true';s.async=true; (google does it that way) or s.async='async'; ?
    – Tobi
    Commented Oct 28, 2010 at 1:03
  • 8
    @Tobias: you're intermingling HTML boolean attributes and the corresponding DOM element properties: the HTML attribute (present in markup and when explicitly setting attributes using setAttribute, which is not recommended) should just be present or being set to either an empty string or itself (defer="defer", especially important when writing XHTML compliant documents); when setting the element's property on-the-fly using JavaScript, one should use s.async = true. Commented Dec 14, 2010 at 16:06
  • 39
    @vsync: It even shouldn't be true; either async, async="" or async="async". Commented Dec 14, 2010 at 16:07
  • 4
    Please note that the post linked in the question sets async="true". It's not the correct way to do it now, but it was the only widely supported way to do it then. For example IE10p2 supported async="true" but did not support async="async" Commented Feb 18, 2014 at 16:10