Which browsers support <script async="async" />?
Asked Answered
A

6

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?

Amaryllidaceous answered 2/12, 2009 at 16:27 Comment(4)
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.Claret
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".Finable
Here is a live test of this attribute html5demo.braincracking.org/demo/async.php.Woodall
This should be a bookmark to check frequently for anyone interested in this issue: en.wikipedia.org/wiki/Comparison_of_layout_engines_%28HTML5%29Lunitidal
C
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
Conventioner answered 2/12, 2009 at 16:33 Comment(6)
I'm not sure you even need async="true", you can just write 'async'Russi
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'; ?Piwowar
@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.Fulmer
@vsync: It even shouldn't be true; either async, async="" or async="async".Fulmer
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"Conventioner
Also see this link to know how to deal with fallback for asych: msdn.microsoft.com/fr-fr/library/ie/hh673524%28v=vs.85%29.aspxKamenskuralski
M
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/

Misdeal answered 20/7, 2011 at 17:49 Comment(0)
P
26

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

Plath answered 7/2, 2012 at 23:23 Comment(1)
An updated view for the parameter can be seen hereReunionist
H
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.

Helices answered 2/12, 2009 at 16:30 Comment(1)
"this new feature" is referring to the HTML5 async attribute. The Google Analytics async snippet is supported by all browsers.Myramyrah
A
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

Arium answered 25/12, 2012 at 18:25 Comment(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 ReviewTapp
@MichaelGaskill Is this enough? Do you want me to link to Philip's answer?Arium
C
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"]
Closefisted answered 22/8, 2013 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.