You can try using jQuery's getScript() function: http://docs.jquery.com/Ajax/jQuery.getScript
On Mar 16, 11:28 am, Scott <sc...@gig.io> wrote: > I'm using an excellent javascript library (the library does not use > jquery if that matters). I need to provide other sites with a > reference to my javascript api (which depends on the above > javascript). However, I don't want other sites to have to enter > something like this: > > <script type="text/javascript" src="http://www.othercompany.com/ > library.js"></script> > <script type="text/javascript" src="http://www.mycompany.com/ > myapi.js"></script> > <script type="text/javascript"> > $('some-div').myapiStart(); > </script> > > Instead, I want to remove that top line bringing in the 3rd party > library. Because I may stop using that library in the future and use > another library. I also want to simplify the javascript code as much > as possible and I very likely will be depending on additional > javascript libraries as well. > > So using jQuery, or even without, is there an easy, reliable and non- > conflict potential way to import javascript within my javascript > code? Am I going to run into any issues (compatibility, conflicts, > xhtml problems, etc) with something like this? > $('head').append('<script type="text/javascript" > src="http://www.othercompany.com/library.js"></script>');