Dynamic Loading of jQuery Libraries

I’ve been going back and forth with my pals @jbhoward (Jim Bob Howard),  @iOnline247(Matt Bramer), and @webdes03(Michael Greene) today about how best to dynamically load jQuery libraries.  We were all interested in the possibility of determining on the fly whether to load the jQuery library itself conditionally from an external CDN (like the Google Ajax Libraries API or the Microsoft Ajax Content Delivery Network).

So I’m thinking about adding a new, separate JavaScript function into the SPServices project for this.  What would your requirements be?

Here’s what I’m thinking so far for options and behavior:

  • An array of src locations for the jQuery library. An attempt would be made to reach each, in order, and the first successful connection would be loaded.
  • A location for the rest of the plug-ins and libraries which need to be loaded
  • An array of the other script libraries to load

I know that there are versions of this out there, but I’m not sure that I’ve seen anything that covers these capabilities well.  If there is, please point me to it!  Otherwise, post your comments about whether the requirements make sense to you and what else you’d like to see.

UPDATE 2010-07-14: Some nice stuff from Einar Stangvik (as usual) here.