Speed Up Google Analytics – Host it Locally
Posted by Jon Lee in Efficiency, Web Development, tags: caching, google, Google-Analytics, speed-up-your-blog
What’s worse than having to wait 10 seconds for a page to load completely? Waiting 11 seconds. Sometimes when a site using Google Analytics loads, you might notice that the status bar says something like:
Transferring data from http://www.google-analytics.com…
What it is doing is fetching urchin.js from the Google servers. Although Google has fast servers, it would make more sense for you to host this file locally since the user already has a connection open to your server.
By having to open another connection, it can freeze the page load until the file is fetched which is why Google recommends the Analytics code be placed at the end of the page right before the </body> tag.
Simply download urchin.js, upload it to your server and point your analytics code to your local version by changing the line:
http://www.google-analytics.com/urchin.js
What if Google Updates urchin.js?
If you’re afraid of the file becoming out-of-date when Google updates urchin.js then you can create a cronjob to periodically download the file to the same location. But keep in mind that the file has updated less than once a year (over the past few years).
How much time would this save?
For returning visitors, not much since urchin.js will be cached the first time the user tries to access your site. Every subsequent time will not require connecting to Google’s servers. However, if your blog gets a lot of one-time visitors (I get hundreds a day), it will give a small speed increase for the user.
Whether or not this speed increase is worth the risk of having an out-of-date urchin.js is up to you. Since it is usually at the end of your code anyway, it may not even matter to you at all!
Popularity: 5% [?]
Entries (RSS)