Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading javascript files in js files. Which is best way to check whether all files are loaded or not?
    primarykey
    data
    text
    <p>I have a array where i have specified the files i need to load in javascript before calling specific script. Lets call those particular lines of code as <code>myscript</code>.</p> <p>I did as follows</p> <pre><code>var fileNamesArray = new Array(); fileNamesArray.push("abc.js"); fileNamesArray.push("pqr.js"); fileNamesArray.push("xyz.js"); fileNamesArray.push("klm.js"); var totalFiles = jQuery(fileNamesArray).length; var tempCount = 0; jQuery.each(fileNamesArray, function(key, value) { jQuery.getScript(value, function() { tempCount++; }); }); </code></pre> <p>to check whether all files are being loaded or not, i done following thing but doesn't seems to be effective</p> <pre><code>var refreshIntervalId = setInterval(function() { if (tempCount == totalFiles) { clearInterval(refreshIntervalId); return; } }, 10); </code></pre> <p>i have implemented these in object oriented javascript as follows</p> <pre><code>function Loader() { this.jQuery = null; // check for specifically jQuery 1.8.2+, if not, load it if (jQuery == undefined) { jQuery.getScript( "/Common/javascript/jquery/map/javascript/jquery-1.8.2.js", function() { this.jQuery = jQuery.noConflict(); }); } else { var jQueryVersion = $.fn.jquery; jQueryVersion = parseInt(jQueryVersion.split('.').join("")); if (182 &gt; jQueryVersion) { jQuery.getScript( "/Common/javascript/jquery/map/javascript/jquery-1.8.2.js", function() { this.jQuery = jQuery.noConflict(); }); } } } Loader.prototype.LoadAllFile = function() { //here i am loading all files } Loader.prototype.bindMap = function(options) { this.LoadAllFile(); //execute the script after loading the files... which we called as myscript } </code></pre> <p>i am loading more than 12-14 js files via ajax.</p> <p>if you observe <code>Loader.prototype.bindMap</code>, i am loading all the files first and then executing the script.</p> <p>But it seems that <code>myscript</code> the script start executing before all files being loaded.</p> <p>what are the better ways to execute the script only after all js files are loaded.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload