Welcome Guest. Sign in or Signup

0 Comments

How to load some Java Script files dynamically and delay calling of document.ready method until all the files are loaded?

Asked by: 1828 views d) Performance

0
0

You can dynamically download some JS files when the page loads based on some condition as follows. Do this in your script block:

var somecondition = true;
if(somecondition === true)
{
	$.holdReady(true);

	$.getScript("www.yoursite/yourJsFile.js", function () {
		// Downloaded the js file
		$.holdReady(false);
	});
}
$(document).ready(function() {
  	// This call will be delayed untill the above js file is loaded.
});

Comments on Question