200

On December 1, 2009, Google announced support for asynchronous Google Analytics tracking.

The asynchronous tracking is achieved using the async directive for the <script> tag.

Which browsers support the async directive (<script async="async" />) and since which version?

4
  • 1
    It's right on that page you linked to: "Firefox 3.6 is the first browser to officially offer support for this new feature" FWIW it's an HTML5 feature, which is quickly gaining better and better support. Commented Dec 2, 2009 at 16:30
  • 51
    The HTML5 spec says that async="true" is illegal. As a boolean HTML attribute, the presence of the attribute indicates "true", while the absence of the attribute equals "false". If the attribute is present, the only valid values for the attribute are "" and "async". Commented Dec 2, 2009 at 17:51
  • Here is a live test of this attribute html5demo.braincracking.org/demo/async.php.
    – user1062963
    Commented Nov 23, 2011 at 23:39
  • 3
    This should be a bookmark to check frequently for anyone interested in this issue: en.wikipedia.org/wiki/Comparison_of_layout_engines_%28HTML5%29 Commented Mar 16, 2012 at 3:59

6 Answers 6

162

The async support as specified by google is achieved using two parts:

  • using script on your page (the script is supplied by google) to write out a <script> tag to the DOM.

  • that script has async="true" attribute to signal to compatible browsers that it can continue rendering the page.

The first part works on browsers without support for <script async.. tags, allowing them to load async with a "hack" (although a pretty solid one), and also allows rendering the page without waiting for ga.js to be retrieved.

The second part only affects compatible browsers that understand the async html attribute

  • FF 3.6+
  • FF for Android All Versions
  • IE 10+ (starting with preview 2)
  • Chrome 8+
  • Chrome For Android All versions
  • Safari 5.0+
  • iOS Safari 5.0+
  • Android Browser 3.0+ (honeycomb on up)
  • Opera 15.0+
  • Opera Mobile 16.0+
  • Opera Mini None (as of 8.0)

The "html5 proper" way to specify async is with a <script async src="...", not <script async="true". However, initially browsers did not support this syntax, nor did they support setting the script property on referenced elements. If you want this, the list changes:

  • FF 4+
  • IE 10+ (preview 2 and up)
  • Chrome 12+
  • Chrome For Android 32+
  • Safari 5.1+
  • No android versions
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
61

There's two parts to this question, really.

  1. Q: Which browsers support the "async" attribute on a script tag in markup?

    A: IE10p2+, Chrome 11+, Safari 5+, Firefox 3.6+

  2. Q: Which browsers support the new spec that defines behavior for the "async" property in JavaScript, on a dynamically created script element?

    A: IE10p2+, Chrome 12+, Safari 5.1+, Firefox 4+

As for Opera, they are very close to releasing a version which will support both types of async. I've been working with them closely on this, and it should come out soon (I hope!).

More info on ordered-async (aka, "async=false") can be found here: http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order

Also, to test if a browser supports the new dynamic async property behavior: http://test.getify.com/test-async/

0
26

A comprehensive list of browser versions supporting the async parameter is available here

1
  • An updated view for the parameter can be seen here
    – Miles
    Commented Oct 7, 2022 at 0:09
10

From your referenced page:

http://googlecode.blogspot.com/2009/12/google-analytics-launches-asynchronous.html

Firefox 3.6 is the first browser to officially offer support for this new feature. If you're curious, here are more details on the official HTML5 async specification.

1
  • "this new feature" is referring to the HTML5 async attribute. The Google Analytics async snippet is supported by all browsers.
    – Brian
    Commented Mar 7, 2010 at 3:09
2

The async is currently supported by all latest versions of the major browsers. It has been supported for some years now on most browsers.

You can keep track of which browsers support async (and defer) in the MDN website here:
https://developer.mozilla.org/en-US/docs/HTML/Element/script

2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Commented Jul 20, 2016 at 17:02
  • @MichaelGaskill Is this enough? Do you want me to link to Philip's answer?
    – brunoais
    Commented Jul 21, 2016 at 14:20
0

Just had a look at the DOM (document.scripts[1].attributes) of this page that uses google analytics. I can tell you that google is using async="".

[type="text/javascript", async="", src="http://www.google-analytics.com/ga.js"]

Not the answer you're looking for? Browse other questions tagged or ask your own question.