How to Fix Issues with SharePoint’s Script on Demand (SOD) System

admin March 6th, 2017

Issues with SharePoint's Script

I recently encountered issues with SharePoint’s script on demand (SOD) system (learn more here http://www.migee.com/2015/09/24/understanding-sharepoint-and-script-on-demand-sod/) that caused me to scratch my head. For this project, we have several custom JavaScript components being loaded on the page, all being initialised using SOD.

Issues with SharePoint's Script

Some of these components are embedded in the master page, and some as web parts in the page. I found however that in IE11, if the script had already been loaded, executeFunc would only fire once, leaving most of my components broken.

Eg:

SP.SOD.executeFunc('myscript.js', null, function(){
    DoSomething(); // this function will get called
});

…

SP.SOD.executeFunc('myscript.js', null, function(){
    DoSomethingElse(); // this will not get called
});

I could resolve this by changing the SP.SOD.executeFunc call to SP.SOD.loadMultiple:

SP.SOD.loadMultiple(['myscript.js'], function () {
    DoSomething(); // this function will get called
});

…

SP.SOD.loadMultiple(['myscript.js'], function () {
    DoSomethingElse(); // this will also work!
});

I haven’t done any performance profiling to test if there’s any difference between the two, however if there is any difference then I certainly don’t notice it.

After making the change, my scripts are now working in all browsers!

If you are still experiencing this issue, please don’t hesitate to reach out. Enter your message here https://fivep.com.au/contact-fivep/.

Thanks.

K.


 

Kieran Cumming | Solution Architect | FiveP

About the author: Kieran’s IT knowledge surpasses that of many elders. He does anything from back-end code to the user interface, he can script or code his way out of any problem.

Comments (0)

Can you relate
to any of these
problems?