Martijn Martijn - 4 months ago 14
Javascript Question

Is it possible to wait until all javascript files are loaded before executing javascript code?

We have several JavaScript files which we load at the bottom of the master page. However, I have the situation that I need to perform some JavaScript before the other scripts are loaded. Is it possible to wait till all the JavaScript files are loaded and then execute some JavaScript code?

I thought

$(document).ready()
did this, but as it turns out, it doesn't. Of course we can move the script files from the bottom to the top, but I am wondering if it's possible what I want.

Answer

You can use

$(window).load();

Which will wait until the page is loaded. $(document).ready() waits until the DOM is loaded