Load scripts in SharePoint within custom Javascript or Workflow
Following is the code which can be used to load JavaScript in sequence.
This code for example loads the reputation.js from SharePoint’s layouts folder & jQuery from site assets.
(function () { ExecuteOrDelayUntilScriptLoaded(function () { //sp.runtime.js has been loaded ExecuteOrDelayUntilScriptLoaded(function () { //sp.js has been loaded SP.SOD.registerSod('reputation.js', SP.Utilities.Utility.getLayoutsPageUrl('reputation.js')); SP.SOD.registerSod('jquery-3.2.1', '../SiteAssets/Scripts/jquery-3.2.1.min.js'); SP.SOD.loadMultiple(['reputation.js', 'jquery-3.2.1'], function () { //reputation.js & jquery-3.2.1.min.js have been loaded. var context = SP.ClientContext.get_current(); var web = context.get_web(); //Check if jQuery has been loaded if (typeof jQuery != 'undefined') { console.log("Jquery is loaded"); } else { console.log("Jquery is not loaded!"); } }); }, "sp.js"); }, "sp.runtime.js"); })();