SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In SharePoint 2013 I have a page that is using the Script Editor web part.
In the script editor web part I have the following:

ExecuteOrDelayUntilScriptLoaded(startIt, "sp.js");

function startIt() {

How come the alert is called when the page is unpublished, but once I publish the page then ExecuteOrDelayUntilScriptLoaded() is not firing. I'm using IE.

Is this a possible bug?

share|improve this question
Any masterpage customisations? Either way, see if sp.js is indeed coming down when the page is published. – James Love Feb 26 '13 at 17:10
No masterpage customizations. This seems to be the exact same issue as… but I dont see any resolution. – NYTom Feb 26 '13 at 17:17
@NYTom I don't understand your comment, there's an answer in the link you posted. – Christophe Mar 12 '13 at 21:55
possible duplicate of SP.SOD how to use correctly? – Hugh Wood Aug 1 '14 at 13:39
This is a possible duplicate of… Execute Or Delay Until Script Loaded is for loaded a script, if its already loaded it won't fire, so you use it in conjunction with execute func – Hugh Wood Aug 1 '14 at 13:41

Here is my fix to the problem.

It seems in SharePoint 2013 calling ExecuteOrDelayUntilScriptLoaded() doesn't work on published pages.

This is the correct way to do it according to Microsoft (see:

// Make sure the SharePoint script file 'sp.js' is loaded before your code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', startIt);
share|improve this answer
In my SP2013, I applied your method on MySite pages. But the function never fire. Do you know why? – Mark Feb 6 '15 at 3:11

As a part of the new Minimal Download Strategy (MDS), sp.js is not loaded by default on published pages.

You will have to load your sp.js explicitly from the /_layouts/15 directory. Example (not tested):


   var fileUrl = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/sp.js";





This change from SharePoint 2010 makes sense in a way that you should only load the sp.js file if you want to make use of the JavaScript Client Object Model. If you are going to use the REST API, you will not need the sp.js file.

share|improve this answer
I looked into SP 2013 MDS and I am using a publishing site. So according to… the MDS feature should be turned off and I check my site settings feature page and it is turned off. So MDS shouldnt be a factor here. – NYTom Feb 26 '13 at 19:24
What I meant was not regarding only the MDS feature. SharePoint 2013 has an overall Minimal Download Policy where it only downloads files which are needed. In 2010, the sp.js used to load on every page even if you were not using it. This caused some performance hit to say the very least. More over, in 2013 you have the REST API which does not require the sp.js file. So if you want to use that file, its the developer's responsibility to load it from his code. – Vardhaman Deshpande Feb 27 '13 at 5:27
Vardhaman, thanks for your help and will look more into the MDS features. – NYTom Feb 27 '13 at 14:06

Your Answer


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.