Image onLoad Technique with 2 js files

  • 0
  • 1
  • Question
  • Updated 5 years ago
  • Answered
How can I utilize the Image onLoad Technique to execute 2 separate scripts?
Photo of dbacks

dbacks

  • 0 Points

Posted 5 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 29,924 Points 20k badge 2x thumb
If script 1 has to finish loading before script 2 can meaninfully run:

var promise1 = $.getScript(url1);
$.when(promise1).then(function(){
var promise2 = $.getScript(url2);
$.when(promise2).then(function(){
//both scripts loaded in sequence - your code here
});
});

OR

If you simply need to hold off running till each script is loaded:

var promise1 = $.getScript(url1);
var promise2 = $.getScript(url2);
$.when(promise1,promise2).then(function(){
//both scripts loaded - your code here
});

OR

QuickBase is now using BackboneJS and RequireJS so could piggyback on using RequireJS as your module loader.