Skip to content

Instantly share code, notes, and snippets.

@ninjasort
Last active August 29, 2015 14:02
Show Gist options
  • Save ninjasort/44f054e61305d1e12d13 to your computer and use it in GitHub Desktop.
Save ninjasort/44f054e61305d1e12d13 to your computer and use it in GitHub Desktop.
Async Function Queueing
var _aq = [],
funcs = [function () {
console.log('Handler 1 executed.');
}, function () {
console.log('Handler 2 executed.');
}];
_aq.push(funcs);
(function() {
var aq = document.createElement('script');
aq.setAttribute('class', 'aq');
aq.async = true;
aq.src = 'http://domain.com/async-exec.js';
var s = document.querySelector('.aq')[0];
s.parentNode.insertBefore(gq,s);
})();
'use strict';
(function (handlers, w, d, u) {
var i;
// executre handlers in queue
for(i = 0; i < handlers.length; i++) {
h = hanlders[i];
h.apply(w, h.arguments);
}
})(_aq, window, document, undefined);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment