Google Analytics Code is Slowing Down My Site
The browser is a liar.
Fast page load is vital for websites. Internet users have a notoriously short attention span, and if a site takes more than a few seconds to load, they leave in droves. Before placing additional code onto a website, it's important to determine whether that will effect page load times negatively.
Does Google Analytics Code Slow Down My Site?
There are two components to consider: the amount of time it takes to download external files (connection speed) and the amount of time it takes for your browser to process JavaScript (processor speed).
The Google Analytics tracking code works by first requesting a file named ga.js from Google's servers. This file defines a series of JavaScript methods, grabs visitor data and creates cookies on the user's machine. This file doesn't change very often, so browsers cache it. In other words, it isn't requested with every visit to every site, let alone with every pageview.
Next, the code requests a 1x1 transparent image named __utm.gif. It attaches information in the query string of this file, and that's how it sends information to Google Analytics. This file is requested with every pageview, but it is 35 bytes. Small enough to be insignificant, regardless of what speed your Internet connection is. It might take 1/100 or 1/50 of a second to load.
Because JavaScript and HTML are executed by the browser from the top down, Google recommends placing the tracking code at the very end of the body just before the closing </body> tag. This way, in the chance that there are any hang ups with Google's servers or (more likely) with the visitors' processor, the rest of the page will still display normally. The worst that will happen is that a pageview won't be reported.
If the tracking code is placed above essential page elements, however, a delay may affect visitors' experiences.
"Waiting for google-analytics.com"
Some have noticed on slow-loading pages that the status message in their browser sometimes says "Waiting for google-analytics.com". This gives the impression that the page is loading slowly because of the tracking code. However, this phrasing is not exactly accurate. What it should say is "Waiting to request from google-analytics.com".
Browsers place priorities on which files need to finish loading before requesting new files. If the tracking code is placed last on a page, as recommended, the __utm.gif file will be the last one requested. If other files on a page are taking a long time to download, browsers will often wait for them to load before sending the request to Google's servers. Our tests on twitter.com, for example, found that slow page loads had less to do with Google Analytics tracking code and more to do with their own files taking too long. In this case, the browser has executed everything else it can and while it's waiting to request the tracking pixel, it displays that misleading message. In other words, it displays that message because the tracking code is last, not because Google's servers are slow.
Troubleshooting
If you are still concerned that Google's tracking code that is slowing down your pageload times, you can try a few things to test its impact:
- Move the code to the very bottom of the page, if you haven't already
- Move another code just after the tracking code to see if it shows up in the status bar instead
- Delete or optimize other large files, like css files and images, to see what impact they are having
- Host the ga.js and __utm.gif file locally and execute the _setLocalServerMode() method. This goes through the same process as normal, except it requests the __utm.gif file locally instead of from Google's servers. (This also means that no data will be sent to your Google Analytics account during the test.)














Comments
Google Analytics slows down webpages
Google Analytics used to offer a simpler (older) code which did less things for you (according to Google).
One thing the old code does NOT do is slow down or block your web page !!
Here it is:
<!-- Start of GoogleAds Code -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxx-y");
pageTracker._trackPageview();
} catch(err) {}</script>
<!-- End of GoogleAds Code -->
"UA-xxxxxx-y" is the unique identifier for your specific website, provided by Google Analytics.
Google Analytics Slowing Page Load Times
Les-
The async code was designed specifically to address latency issues that might get caused by the older code you cite. It doesn't actually have any more functionality. I haven't heard anybody complain about the async code slowing down or blocking web pages. I'd be interested to know what your experience has been.