<html>
<head>
<title>Example 1</title>
<script>

var event_queue = [];
var the_event = null;

// CENTRAL_HANDLER:
// called by onload and setTimeout
function central_handler() {
    if (!(event_queue.length > 0)) {
      return;
    }
    the_event = event_queue.shift();

    // call event
    window[the_event.name]();

    // only loop until the stack is empty
    if (event_queue.length > 0) {
       setTimeout(function () {
                    central_handler();
                  },
                  the_event.delay);
    }
}

function init() {
 document.getElementById("root").innerHTML = "NOT preloaded";
}

</script>

</head>

<body onload="event_queue.push({'name':'init','delay':2000}); central_handler();"\>

<div id="root">
Preloaded
</div>

</body>
</html>