Question

What is meaning of OnDemand scripts and what is not-on-demand scripts?

In SharePoint 2013, when do we use SP.SOD.executeFunc and when to use ExecuteOrDelayUntilScriptLoaded ?

What is best practice?

Was it helpful?

Solution

On Demand scripts are the one which we load only when we need it in a page. We put a reference to it but it won't load until we call for it instead of the usual one which gets loaded every time the page loads. A very good blog on this could be found here

ExcuteOrDelayUntilScriptLoaded does not trigger loading an on demand script (SOD)! It schedules an asynchronous callback function which will be called when the script has signaled finished loading.

SP.SOD.executeFunc is used to load on demand scripts (ScriptLink.OnDemand=true). From the link I mentioned above

The idea of on demand script loading make really sense. SharePoint 2010 loads really a lot of JavaScripts - this takes time! So the idea is: first load the HTML and let it render by the browser so that the user is able to read the requested information as fast as possible. And in the second step load the behavior (the JavaScripts).

Best practice is to use On demand scripts as and when possible as it reduces page load time considerably.

One more thing to remember is SP.SOD works closely with ScriptLink server control. Check the links attached for more info on these.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top