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.

New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

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.

Check out Best Alternative to InfoPath -> Try Now


(Installation & Features)