curious1
curious1

Reputation: 14717

Embed Javascript on pages that loads other javascript libraries?

I am doing a web application, which is planned to allow other websites (client) to embed the following javascript on its page:

<script src="http://example.org/my.js"></script>

My web application is at http://example.org.

I cannot assume that the pages at the client websites have JQuery and other needed libraries. So it seems that the javascript my.js needs to load needed JQuery AND other javascript libraries.

From this article : How to build a web widget (using jQuery) at

http://alexmarandon.com/articles/web_widget_jquery/

I know how to load needed JQuery. What about loading other libraries? It seems its going to be complicated if I use the code in the above article to load multiple javascript libraries.

How or any Javascript library to help me load multiple javascript libraries (or even more, css files) easily?

Thanks!

Upvotes: 0

Views: 129

Answers (1)

Aameer
Aameer

Reputation: 1376

to load other js files from one js file,you can include this code snippet, you can add different scripts with this method

var server_name="abc.com"
(function() {
var some_scrpt = document.createElement('script'); some_scrpt.type = 'text/javascript'; some_scrpt.async = true;
some_scrpt.src = 'http://' + server_name + '/static/js/your_script.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body'[0]).appendChild(some_scrpt);
})();

Hope it helps.

Upvotes: 1

Related Questions