Unfortunately, my website renders currently somewhere between half a second and one full second.
Unfortunately, my website renders currently somewhere between half a second and one full second.
Google Analytics, I have noticed, can really be quite a drag on page loading speed.
This is quite unfortunate. So, I looked for a solution. Some people host the urchin.js file on their own server, and have an automated task which downloads the current copy a couple of times a day to keep up to date. This solution did not seem proper to me, given that Google specifically states that it should not be, and that I don't really want to set up my server with a component to auto-download the script.
So, on my site, I made the script be loaded on-demand through one of my own Javascript functions. This function, which runs after all of my initialization has completed, adds a new script object to the document, runs a test every tenth of a second to check if it has completed loading, and then runs the urchinTracker() command. It took a bit of doing, but it appeared to work, and there was apparently no waiting for Google's sometimes-slow servers for my site to initialize properly - it only would only wait AFTER everything has initialized.
Unfortunately, this did not work. The Google Analytics code would not call. As I am too busy to figure out why, I have replaced it. However, a few other edits are still in place - the initialization script now calls before the images have loaded, and before Google's code has loaded. This makes things appear much faster.