SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

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

I am trying to use a .js file to highlihgt nodes in a top navigation menu based on url of the current web. The javascript file is provisioned by a Module in a Empty SharePoint 2013 project item. The problem is that it never comes to my method. It seems sp.js is never loaded. I have used ExecuteOrDelayUntilScriptLoaded and LoadSodByKey methods like following:

   LoadSodByKey("sp.js", function () {
        $(function () {
            //alert("sp.js loaded");

    ExecuteOrDelayUntilScriptLoaded(function () { SP.UI.Workspace.add_resized(MyMethod); },

   function MyMethod() {
      currentcontext = new SP.ClientContext.get_current();

    currentweb = currentcontext.get_web();
    currentuser = currentweb.get_currentUser();
    rootWeb = currentcontext.get_site().get_rootWeb();

    currentcontext.load(rootWeb, 'EffectiveBasePermissions', 'ServerRelativeUrl', 'Id');
    currentcontext.executeQueryAsync(Function.createDelegate(this, ExecuteOnSuccess), Function.createDelegate(this, ExecuteOnFailure));

    //and ExecuteOnSuccess , ExecuteOnFailure


share|improve this question
Is your JS file actually referenced in the page? – James Love Jan 24 '13 at 19:58
What happens if you run _spBodyOnLoadWrapper() manually, and perhaps try 'SP.js', although I don't think it should be case sensitive. – eirikb Jan 24 '13 at 20:39
Thanks guys, Yes the js file is referenced from my master page (my methoded get hited when you use documment(ready). I have tested it when I hit f12 and check the files have been loaded, there is no sp.js but all other js files i.e. core.js ... – Medes Jan 24 '13 at 22:06
up vote 3 down vote accepted

In SharePoint 2013 as a part of Minimal Download Strategy, there are few OOB js files that don't load as they used to be in SP 2010. These include files like SP.js , SP.Runtime.js etc. So, you need to explicitly add references to these files. Either you can directly add the reference of SP.Runtime.js and SP.js in your master page or you can use getScript to load these files.

        var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
        $.getScript(scriptbase + "SP.Runtime.js",
            function () {
                $.getScript(scriptbase + "SP.js", YourMethod);


Can you try the above code snippet and see if it helps.

share|improve this answer

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.