Skip to content

Instantly share code, notes, and snippets.

@cameronroe
Last active Aug 29, 2015
Embed
What would you like to do?
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