I am currently using LABjs to defer loading of scripts and in sub pages I am pushing into the queue for inline script like so.
<script> var _loadingQueue = [];</script>
<script>
_loadingQueue.push(function(){
var scheduledPmtData = {'PaymentCount' : 0};
...snip...
});
</script>
then inside my main $LAB
I do
if( typeof( window[ '_loadingQueue' ]) !== "undefined"){
for(var i=0,len=_loadingQueue.length; i<len; i++){
$LoadDefer = $LoadDefer.wait(_loadingQueue[i]);
}
}
My inline script has come to the point that I want to put it in an external JS file. How do I keep the same type of loading but as a script file not inline?
This is what I did to get it working. If it can be refactored, please let me know.
Added another var
<script> var _loadingQueueScript = [];</script>
Then where the inline code was, I did
<script>
_loadingQueueScript = "/assets/scripts/source/addevent.js";
</script>
Then under my previous $LoadDefer.wait()
I added
if( typeof( window[ '_loadingQueueScript' ]) !== "undefined"){
$LoadDefer = $LoadDefer.script(_loadingQueueScript);
}