tags:

views:

112

answers:

3

Is it better (in any way) to use jQuery's getScript to load the external JS than linking the javascripts manually in the html?

A: 

Can you rephrase the question? Linking them manually in the html? You mean, the urls to the scripts? You could generate them with your back-end (whatever that may be)... but... of course you need a url to load a script and jQuery can't -- I don't know -- guess or something :)

thenduks
+2  A: 

If the javascript file you want to load is somewhat optional, e.g. for a specific browser or maybe geolocation, i'd use getScript; otherwise I'd see no need to push the 'include' further down in the page loading process than a plain html script.

If you are concerned about performance, i would guess that the 'plain-method' is faster, but I haven't tested it. For web page load time performance tuning, there is a nice tool, called yslow, which is a firebug extension.

The MYYN
+1  A: 

You may want to delay loading and executing the script until you need it - the page will load faster if it is loaded dynamically.
In addition, the callback is very handy.

Kobi