Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to delay loading external JS file (Google Analytics)?
    primarykey
    data
    text
    <p>I'm using the following code to load my Google Analytics (external javascript) in a way that is meant to <strong>not</strong> block rendering.</p> <p>However, using both YSlow and Safari Web Inspector - the network traffic clearly shows that the ga.js script is still blocking rending.</p> <pre><code>/* http://lyncd.com/2009/03/better-google-analytics-javascript/ Inserts GA using DOM insertion of &lt;script&gt; tag and "script onload" method to initialize the pageTracker object. Prevents GA insertion from blocking I/O! As suggested in Steve Souder's talk. See: http://google-code-updates.blogspot.com/2009/03/steve-souders-lifes-too-short-write.html */ /* acct is GA account number, i.e. "UA-5555555-1" */ function gaSSDSLoad (acct) { var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."), pageTracker, s; s = document.createElement('script'); s.src = gaJsHost + 'google-analytics.com/ga.js'; s.type = 'text/javascript'; s.onloadDone = false; function init () { pageTracker = _gat._getTracker(acct); pageTracker._trackPageview(); } s.onload = function () { s.onloadDone = true; init(); }; s.onreadystatechange = function() { if (('loaded' === s.readyState || 'complete' === s.readyState) &amp;&amp; !s.onloadDone) { s.onloadDone = true; init(); } }; document.getElementsByTagName('head')[0].appendChild(s); } /* and run it */ gaSSDSLoad("UA-5555555-1"); </code></pre> <p>Any ideas on how I can use JavaScript to delay the loading of the ga.js file, because the code above doesn't appear to do as it intends, until the entire page has been rendered so that I don't block rendering?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload