Asynchronous Google Analytics snippets (v25)

Revision 25 of this benchmark created on


Test case which measures the speed difference between the default asynchronous Google Analytics snippet and the optimized version.

Note that I commented out the s.parentNode.insertBefore(g, s); line in both scripts, since otherwise the <script> element gets inserted a few thousand times every time you run the tests. Since this code is the same in both scripts, it shouldn’t have an influence on the results.

Test runner

Ready to run.

Testing in
Default snippet
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
(function() {
  var ga = document.createElement('script');
  ga.type = 'text/javascript';
  ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
  var s = document.getElementsByTagName('script')[0];
  // s.parentNode.insertBefore(ga, s);
Optimized snippet
var _gaq = [
  ['_setAccount', 'UA-XXXXX-X'],
(function(d, t) {
  var g = d.createElement(t),
    s = d.getElementsByTagName(t)[0];
  g.async = g.src = '//';
  // s.parentNode.insertBefore(g, s);
}(document, 'script'));


You can edit these tests or add more tests to this page by appending /edit to the URL.