I need to create a simple javascript embed type thing where the user adds a small amount of javascript to their site and my script does the rest.
This is the sort of thing I would like to see on the user site:
Included once:
<script type="text/javascript" src="path/to/doEverythingScript.js"></script>
And this in the HTML:
<div id="target-div">
<script type="text/javascript">
doThis(1714581, "#target-div");
</script>
</div>
I would also need to be able to have multiple versions running on the same page.
The id (eg: 1714581) is passed to my function along with my target div.
This issue is I need to have the one script load all the dependancies:
eg:
path/to/style1.css
path/to/style2.css
path/to/style3.css
path/to/jquery.js
path/to/script1.js
path/to/script2.js
path/to/script3.js
path/to/script4.js
And once they are all loaded I would then be able to run my function.
If my function ran before they all loaded It naturally wouldn’t work.
I tried using LazyLoad and LAB but couldn’t work out how to have one JS file sort all this out with only one linkied script and a small function on the page.
What I have writen so far doesnt work becuas the function tries to run before the dependecies are loaded.
Any help with this issue is much appreciated.
Let this be your loaded script (configure the first block to meet your wishes). On request of the OP, I’ve also added a queue function.
Note: Add
_REQUIRED_instead of an external resource, if you want to delay loading additional scripts until the previously requests has been finished.In your HTML source: