Question

Let's say you're loading a bunch of super heavy images with a js preloader (Preload.JS) and in the callback you have your $(document).ready function.

Example code:

var queue = new createjs.LoadQueue();

queue.loadManifest([
    "img/1.jpg",
    "img/2.jpg",
    "img/3.png"
]);

queue.on("complete", preloadComplete, this);

function preloadComplete() {

    $(document).ready(function() {
        //jquery stuff
    });
}

Is it possible that the preloading could take so long that the ready function gets missed?

Was it helpful?

Solution

The ready function can't be "missed". Even if the document is already ready, the function within it will run.

http://api.jquery.com/ready

If .ready() is called after the DOM has been initialized, the new handler passed in will be executed immediately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top