# Asynchronous script tag is blocking

**URL:** <https://forum.kirupa.com/t/asynchronous-script-tag-is-blocking/312488>\
**Category:** web dev\
**Created:** [August 4, 2010, 7:04pm UTC](https://forum.kirupa.com/t/asynchronous-script-tag-is-blocking/312488 "2010-08-04T19:04:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [August 4, 2010, 7:04pm UTC](https://forum.kirupa.com/t/asynchronous-script-tag-is-blocking/312488/1 "2010-08-04T19:04:08Z")

</div>

Google Analytics claims to have a way to asynchronously load their script. You put this at the bottom of \<body\>:

```php

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
 
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
    'https://ssl' : 'http://www') +
    '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();

```

The _async_ attribute works in Firefox 3.6+. I claim that it’s not asynchronous at all on my FF 3.6.8. Here’s my test. I changed the the code to:

```php

(function() {
    var ga = document.createElement('script');
    ga.src = '/sleep.php';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();

```

sleep.php:

```php

<?php
    sleep(5);
?>

```

This has slowed down my website by 5 seconds! My main JS code relies on the window load event to manipulate the DOM. This simulation of a slow loading Google Analytics has pushed back the window load event by 5 seconds. And believe me, Google Analytics has been slow on more than one occasion! So am I just not understanding what the _async_ attribute is supposed to do?
