Christof Donat wrote: > > No. In your example b.js is completelly evaluated before the doA() is > called, > but that only means, that the download of c.js has been started. As soon > as > that has finished, doB() is called, but that can be after doA() has been > called. > > $.getScript() initiates the download and takes care that the callback is > called after the download will have finished and then immediatelly > returns. > Some time later the download actually has finished and then the script is > evaluated and the callback is called. > > The result for your example is: > > a.js: $.getScript('b.js',doA); > - b.js begins to load > a.js has finished > - b.js is completely loaded > b.js is evaluated -> > $.getScript('c.js',doB); > - c.js begins to load > b.js has finished -> doA() is called > - c.js is completely loaded > c.js is evaluated -> doC(); > c.js has finished -> doB() is called > > As you see the order will be doA(), doC(), doB(). >
Wow! This is a good explanation! I undestand now, thank you Christof! So, if I want getScripts to wait until all is loaded and evaluated at all levels before going on, I cannot use this method, as you noted before. I think that this facility (being able to load many scripts without declaring them in the html) will make jQuery easier to use. An alternative could be to inspect any loaded script and see if it requires more scripts (recursively). If it does (like b.js), then I could find a way to transform [a.js// $.getScript( "b.js", function() { doA(); } ); ][b.js// $.getScript( "c.js", function() { doB(); } ); ] into [a.js// $.getScript( "c.js", function() { doB(); doA(); } ); ]. And condidering that I'm not interested in providing this functionality in the wild, but only for jQuery plugins, I could enforce a standard format where any script declares the scripts it requires at the beginning. Another alternative could be to have a little module on the server. A script does a normal getScript with an url like [ /make/?a.js ] and the make module buids a file with all the needed parts, then packs and serves it. -- View this message in context: http://www.nabble.com/Working-on-a-getScripts-plugin-tf2696465.html#a7527956 Sent from the JQuery mailing list archive at Nabble.com. _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/