+11  A: 

You can take a look at dynamic script loading. Here's an excerpt from the article:

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'helper.js';
head.appendChild(script);
Darin Dimitrov
thanks just what i was looking for
mark smith
+1  A: 

Google offers centrally hosted versions of the major javascript libraries like jQuery. They can be dynamically loaded using the google loader.

http://code.google.com/apis/ajaxlibs/documentation/

emills
+2  A: 

This is similar to Darin's solution, except it doesn't make any variables.

document.getElementsByTagName('head')[0].appendChild(document.createElement("script")).src = "helper.js";
Eli Grey
Or you could just wrap the more readable solution in `(function() {...})();`
eyelidlessness
+1  A: 

I'd suggest you take a look at labJS. It's a library made specifically to load Javascript. As they say..."The core purpose of LABjs is to be an all-purpose, on-demand JavaScript loader, capable of loading any JavaScript resource, from any location, into any page, at any time."

See the labJS home page for more information.

Bill Barnhill
+1  A: 

For external domain JS link

var loadJs = function(jsPath) { 
    var s = document.createElement('script');
    s.setAttribute('type', 'text/javascript');
    s.setAttribute('src', jsPath);
    document.getElementsByTagName('head')[0].appendChild(s);
};
loadJs('http://other.com/other.js'); 

For same domain JS link (Using jQuery)

var getScript = function(jsPath, callback) {
    $.ajax({
        dataType:'script',
        async:false,
        cache:true,
        url:jsPath,
        success:function(response) {
            if (callback && typeof callback == 'function') callback();
        }
    });
};
getScript('js/other.js', function() { functionFromOther(); }); 
molokoloco