Enable sp.js in Publishing Pages in SharePoint 2013

In this tutorial, we will discuss how to enable sp.js in Publishing Pages in SharePoint 2013. By default, sp.js is not visible in publishing pages. 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:

1. Add a script editor web part in your page and in script tags just add the following code snippet:

SP.SOD.executeFunc(‘sp.js’, ‘SP.ClientContext’, sharePointReady);

Where sharePointReady is a method which will be executed after sp.js is loaded.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)


Siddharth Pal