One more easy way is to do it using ScriptManJS library. It makes sure dependencies are loaded correctly and you do not have to bother about it when using ScriptManJS.
1) Add script tag to the head section of html to include the library:
<script type="text/javascript" src="scriptman.min.js"></script>
2) Somewhere in beginning of code add:
new ScriptMan();
3) Perform inclusions in one of the possible syntaxes. I will provide several options how to do that just a broader picture. I am sure you will choose the one which will best suit your needs:
Option 1:
Just include two files - no additional code is needed when they are loaded.
S.require( [
'file_with_your_object.js',
'third_party.js'
], {
sync: true
} );
// Files may not be loaded yet when executing code here
Option 2:
If object is defined in main file, it becomes simple as this.
var yourObject = { /* Object contents */ };
S.require( 'third_party.js' );
// Files may not be loaded yet when executing code here
If you do not like the fact that file may not be loaded yet below this fragment, modify the last line to this:
S.require( 'third_party.js' ).then( function() {
// Here third_party.js will definitely be loaded
} );
// Here third.party.js may not be ready yet
Option 3
Same as option 1 - different syntax.
S.require( 'file_with_your_object.js' ).then( function() {
S.require( 'third_party.js' );
} );
Option 4:
How I would do it with ScriptManJS.
file_with_your_object.js
return { /* Object contents */ };
main file (i.e. index.html)
S.require( 'file_with_your_object.js' ).then( function( yourObject ) {
S.require( 'third_party.js' ).then( function() {
// Everything is loaded and yourObject contains your object here
} );
} );
Or even like this (in main file):
S.require( [
'file_with_your_object.js',
'third_party.js'
], {
sync: true
} ).then( function( yourObject ) {
// Everything is loaded and yourObject contains your object here
} );
If for some reason third party library would not like to be included like that (low probability), you can add one more option next to sync:
...
{
sync: true,
nakedFiles: [ 'third_party.js' ]
}
...
Hope this helps :)