Skip to content

Instantly share code, notes, and snippets.

@ekashida
Last active December 18, 2015 09:39
Show Gist options
  • Select an option

  • Save ekashida/5762890 to your computer and use it in GitHub Desktop.

Select an option

Save ekashida/5762890 to your computer and use it in GitHub Desktop.
Tests that check what the DOM reports for script nodes that Y.Get inserts based on whether the transaction is `async:true` or `async:false`.
YUI().use('json-stringify', function (Y) {
var ua = {};
Y.Object.each(Y.UA, function (v, k) {
if (v) {
ua[k] = v;
}
});
log(Y.JSON.stringify(ua, null, 4));
var supportsAsync = document.createElement('script').async === true;
// IE10 doesn't return `true` for the above feature test.
supportsAsync = supportsAsync || Y.UA.ie >= 10;
if (supportsAsync) {
log('This browser DOES support async script tags');
} else {
log('This browser DOES NOT support async script tags');
}
// ----- async: true
var asyncScript = document.createElement('script');
asyncScript.async = true;
log('[async: true] script.getAttribute("async") returns ' + getType(asyncScript.getAttribute('async')));
log('[async: true] script.async returns ' + getType(asyncScript.async));
// ----- async: false
var syncScript = document.createElement('script');
if (supportsAsync) {
syncScript.async = false;
} else {
// insert scripts serially
}
log('[async: false] script.getAttribute("async") returns ' + getType(syncScript.getAttribute('async')));
log('[async: false] script.async returns ' + getType(syncScript.async));
});
// We're only interested in booleans, undefined, and null.
function getType (value) {
var type = typeof value;
if (type === 'object') {
type = 'null';
}
return type;
}
function log (msg) {
if (window.console && console.log) {
console.log(msg);
} else {
alert(msg);
}
}

Browsers that support async script tags

Chrome latest (27.0.1453.110)

{
    "webkit": 537.36,
    "chrome": 27.01453,
    "os": "macintosh",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36"
}

This browser DOES support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns boolean

Safari latest (6.0.4)

{
    "webkit": 536.2913,
    "safari": 536.2913,
    "os": "macintosh",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.29.13 (KHTML, like Gecko) Version/6.0.4 Safari/536.29.13"
}

This browser DOES support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns boolean

Firefox latest (21.0)

{
    "gecko": 21,
    "os": "macintosh",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0"
}

This browser DOES support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns boolean

IE 10

{
    "ie": 10,
    "os": "windows",
    "userAgent": "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; .NET4.0E; .NET4.0C)"
}

This browser DOES support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns boolean

Android 4.x

{
    "webkit": 534.3,
    "safari": 534.3,
    "mobile": "Android",
    "android": 4.11,
    "os": "android",
    "touchenabled": true,
    "userAgent": "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; SAMSUNG-SGH-I747 Build/JRO03L) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30)"
}

This browser DOES support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns boolean

iOS Safari 5.x

{
    "webkit": 534.46,
    "safari": 534.46,
    "mobile": "Apple",
    "ipad": 5.1,
    "ios": 5.1,
    "os": "ios",
    "touchenabled": true,
    "userAgent": "Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3"
}

This browser DOES support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns boolean

iOS Safari 6.1

{
    "webkit": 536.26,
    "safari": 536.26,
    "mobile": "Apple",
    "iphone": 6.1,
    "ios": 6.1,
    "os": "ios",
    "touchenabled": true,
    "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B350 Safari/8536.25"
}

This browser DOES support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns boolean

Browsers that don't support async script tags

Android 2.3.4

{
    "webkit": 533.1,
    "safari": 533.1,
    "mobile": "Android",
    "android": 2.34,
    "os": "android",
    "touchenabled": true,
    "userAgent": "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; SPH-P100 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1)"
}

This browser DOES NOT support async script tags

  • [async: true] script.getAttribute("async") returns null
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns undefined

IE 6

{
    "ie": 6,
    "os": "windows",
    "userAgent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
}

This browser DOES NOT support async script tags

  • [async: true] script.getAttribute("async") returns boolean
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns undefined

IE 7

{
    "ie": 7,
    "os": "windows",
    "userAgent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
}

This browser DOES NOT support async script tags

  • [async: true] script.getAttribute("async") returns boolean
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns undefined

IE 8

{
    "ie": 8,
    "os": "windows",
    "userAgent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"
}

This browser DOES NOT support async script tags

  • [async: true] script.getAttribute("async") returns string
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns undefined

IE 9

{
    "ie": 9,
    "os": "windows",
    "userAgent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
}

This browser DOES NOT support async script tags

  • [async: true] script.getAttribute("async") returns null
  • [async: true] script.async returns boolean
  • [async: false] script.getAttribute("async") returns null
  • [async: false] script.async returns undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment