Monday, September 19, 2005

Urchin Javascript and onLoad Content

Someone asked me the other day if the Urchin javascript can affect or delay the loading of a website. In most cases the answer is no. But, there is a case that developers should be aware of. This really isn't specific to Urchin, and can occur anytime you are sourcing external javascript or other content. If your site creates dynamic content using an onLoad function or similar operation, then read on.

The issue occurs in Firefox/Safari/Mozilla browsers which have synchronous javascript operations that require everything to be loaded before executing the code in an onLoad call. If there is a delay in the execution or loading of any of the javascript on the page, then the javascript calls in the onLoad event will wait for the previous execution to complete. This is not an issue in IE.

So what does this mean for my dynamic site? It is possible that a delay in the execution of the Urchin tracking could delay the loading of your webpage if part of your page is displayed using the javascript onLoad function. While delays in Urchin tracking are rare, it is recommended to trigger the Urchin tracking to occur after the loading of the entire page. This is easily done by manually calling the "urchinTracker();" function after your other onLoad content. Here is how to do this:

1. First, edit your Urchin Javascript (__utm.js) and comment out the line that calls urchinTracker(); using // in front of the line.
2. Then in your onLoad call, add the urchinTracker to the end of your javascript, for example:

< body onload="myfunction(); urchinTracker();" >

This will delay the calling of the Urchin tracking system until the page has completely loaded. Any delay in executing the Urchin tracking will not affect the loading of the page since it comes after.