What is it that you are actually trying to do? Looking at your code makes me wonder whether you are loading images that are generated in real-time - like in a security console - in which case the entire idea of "pre-loading" goes out of the window because you are always loading images that didn't exist before.
If that is the case you may need to vary your approach:
When the load is complete replace the stale image element with the fresh one. Also use setInterval to schedule the next asynchronous loading of the next, more current image after ?? seconds (The ?? delay is primarily there to give the server a break - especially if you have a separate asynchronous request going for each image that is currently visible on the document).
Bear Bibeault wrote:Be sure to remove the console statements before building for production. They will cause failures in browsers when the debugger isn't enabled.