Enable SP.JS in publishing sites for SP 2013

Hi,

In my previous post, I have explained the way to add CSOM on master page of any kind of site. But later on when testing same code with publishing site, I realized that sp.js is not loaded on publishing site by default.

So in this post I will discuss how to enable sp.js in Publishing Pages in SharePoint 2013. As the SharePoint uses minimal download strategy it prevents the page to have sp.js when published but the point to note is when you open your ribbon bar (edit or unpublished state) sp.js  script gets loaded in your page .
Note : SharePoint loads scripts on Demand


So to solve this we can do like this: Add a script editor webpart in your page and in script tags just add the following code snippet:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', alert('I have loaded the sp.js script.'));


Where instead of alert method you can use any JS method and will be executed after sp.js is loaded.


Happy SharePointing :).

Comments

Popular posts from this blog

Hide Ribbon on SharePoint 2013 using CSS

Get Comment Count in SharePoint

Configure external site as content sources in sharepoint search