New Asynchronous Script Stops Google Analytics From Slowing Down Your Site
Google Analytics is one of the more popular ways to keep track of your site’s visitors. With the ability to track, compare and compile all sorts of statistics about who’s visiting your site, Google Analytics is hard to beat.
However, Google is now offering a second possible solution — a new Google Analytics script that loads asynchronously.
The asynchronous script means browsers will load the ga.js script file separately from the rest of your page, minimizing the impact on page rendering.
The net result is that you can move your Analytics code back up to the head tags of your pages and it won’t slow down your pages. Or rather it will, but it won’t be noticeable to users. In our testing, the new script loaded in between 80ms-120ms, whereas the old script loaded in 40ms-60ms.
The new script is definitely slower, but because it loads separately from the rest of your code visitors will see all your content before the new script kicks in, even if it’s at the top of the page.
In our testing, the overall page load time for the new script in the head tags was almost exactly the same as for the old script at the bottom of your page.
The new script and some new embed code can be found on Google Code. Keep in mind that the new script is still a beta, which means you might want to hold off using it on production sites.