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?

1 Answer 1


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.

  • Do you mean that we cannot use ExcuteOrDelayUntilScriptLoaded together with on-demand scripts? Can you give me example of on-demand scripts.?
    – variable
    Jul 22, 2014 at 11:16
  • Yes, for on-demand scripts we need SP.SOD.executeFunc(). You will get an example here ilovesharepoint.com/2010/08/…. Example 2 is for OnDemand=true there is a typo in there.
    – Garima
    Jul 22, 2014 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.