i like to do a simple javascript execution with MDS and without MDS.

To do this, I have used this Javacript only executed on first page load HowTo to get work.

The Problem i have, is that the script only is run once time. With a MDS Delta and a direct invoke.


Both link works great for one time. When i now go to home and back to the test link, my script will not run.

Here are my scripts:


<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<meta name="CollaborationServer" content="SharePoint Team Web Site" />
<SharePoint:ScriptBlock runat="server">
<SharePoint:ScriptLink language="javascript" name="~site/SiteAssets/jquery.min.js" OnDemand="false" runat="server" Localizable="false"/>
<SharePoint:ScriptLink language="javascript" name="~site/SiteAssets/mycode.js" OnDemand="false" runat="server" Localizable="false"/>
var navBarHelpOverrideKey = "WSSEndUser";
<SharePoint:RssLink runat="server" />


function myCode(){
// jQuery code goes here
// you can use $ namespace

function preCode(){
if(typeof _spPageContextInfo != "undefined" && _spPageContextInfo != null){

     var jsURL = _spPageContextInfo.siteServerRelativeUrl + "/SiteAssets/mycode.js";
     RegisterModuleInit(jsURL, myCode());
     ExecuteOrDelayUntilScriptLoaded(preCode, "sp.init.js"); 

Can anyone tell me my fault? I am frustrating.

Thanks for all your help.

1 Answer 1


The whole essence of MDS is not to load (and execute) the same scripts again.

You have to hook into the asyncDeltaManager to tell MDS you want something executed beside the initial load.

  //run on every MDS request

There are more MDS events you can hook into: pageLoad, pageLoading, endRequest

Note that with MDS anything you add to the DOM will not get deleted on page transitions

Note 2: You can add jQuery inside the JSLink setting, you can separate multiple JS file references with a | (pipe) symbol

  • Hey Danny, thanks for your quick reply. Where i have to embed the asyncDeltaManager? In the function mycode() ?
    – user25772
    Commented May 9, 2016 at 12:40
  • It is the same concept as the PageRequestManager you already use. Commented May 9, 2016 at 12:42
  • When i am using the jslink, sharepoint only execute it once time. So i got the same problem again. Or do i have to use a specific function from sharepoint?
    – user25772
    Commented May 10, 2016 at 6:34
  • MDS will execute any JS code only once, the brute force method is to disable the MDS feature in Site Settings Commented May 10, 2016 at 7:28

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.