(function () {var f = function () { function loadChains(chains, limit, onChainDone) { function newImageLoader(url) { return function () { var e = new Image(); addListeners(e); e.src = url; }; } function newScriptLoader(url) { return function () { var e = document.createElement('script'); e.type = 'text/javascript'; e.async = true; addListeners(e); e.src = url; document.head.appendChild(e); }; } function newIframeLoader(url) { return function () { var e = document.createElement('iframe'); e.style.display = 'none'; e.width = 1; e.height = 1; addListeners(e); e.src = url; document.body.appendChild(e); }; } function addListeners(e) { addLoadErrorListeners(e, loadNext); if (typeof onChainDone === 'function') { addLoadErrorListeners(e, onChainDone); } } function addLoadErrorListeners(e, listener) { if (typeof e.addEventListener === 'function') { e.addEventListener('load', listener, false); e.addEventListener('error', listener, false); } else if (typeof e.attachEvent === 'function') { e.attachEvent('onload', listener); e.attachEvent('onerror', listener); } } function loadNext() { var next = loaders.shift(); if (typeof next === "function") { setTimeout(next); } } var loaders = chains.reduce(function (acc, value) { var mode = value[0]; var url = value[1]; switch (mode) { case 'image': acc.push(newImageLoader(url)); break; case 'script': acc.push(newScriptLoader(url)); break; case 'iframe': acc.push(newIframeLoader(url)); break; } return acc; }, []); for (var i = 0; i < limit; i++) { loadNext(); } } var chains = []; chains.push(['image', 'https://id.rlcdn.com/463636.gif']); loadChains(chains, 10, (typeof onDone === "function") ? onDone : null); }; if (document.body) { f(); } else { document.addEventListener('DOMContentLoaded', f); } }());