Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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 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 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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