When the script loads, it will be executed as soon as possible. That is, if any other javascript function is executed, for example, a click manipulator or something else, it will be allowed to complete first, but this is set because, as you say, JavaScript usually runs in a single thread in browsers.
You cannot control this part of the script loading, but you can use this template - strongly inspired by JSONP:
script inserted:
(function () {
var module = {
init: function () {
}
}
ready(module);
}());
script on the main page:
function ready(o) {
setTimeout(function () { o.init(); }, 1000);
}
- ready, , script, . , , script , , init , .