I have a page on my sharepoint site, when i'm on the edit page the javascript works however when I have published the page, the javascript doesn't work. I have added the link to the javascript file in some embedded code. any help would be appreciated


3 Answers 3


It's a known issue for a publishing pages (here or here), sp.js library is loaded in the edit mode but not in the display mode.

As part of Minimal Download Strategy (MDS) that was introduced in In SharePoint 2013, SharePoint JavaScript libraries like sp.js are not loaded until explicitly called.


Utilize SP.SOD.executeFunc method to load SharePoint JavaScript libraries on demand, for example:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){

    //your code goes here...

  • Hello Vadim where do I put the SP.SOD.executeFunc in my code? Does it go in my sp.js file or my page somewhere? Commented Aug 17, 2017 at 17:14
  • That's right, sp.js is a part of core JS library and it is getting loaded with every page in SharePoint Commented Aug 17, 2017 at 18:26

You need to apply the type or language attribute to any <script> tags being used in a Script editor web part.

type='text/javascript' or language='javascript'

For example: <script type='text/javascript' src="js/app.js"></script>

See Script Editor only runs JavaScript in edit mode


Is your javascript placed inside PublishingWebControls:EditModePanel?

If yes, check if the pagedisplaymode is correct!

If you want the javascript to be run in both (edit/display) just place the javascript outside the PublishingWebControls:EditModePanel

<!-- Display mode only -->
<PublishingWebControls:EditModePanel runat="server" 

<!-- Edit mode only -->
<PublishingWebControls:EditModePanel runat="server" 

documentation to editmodepanel


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.