2

I added references to jQuery and bootstrap to a master page using the <SharePoint:ScriptLink> control:

<SharePoint:ScriptLink language="javascript" name="~sitecollection/SitePages/scripts/jquery-1.9.1.min.js" OnDemand="true" runat="server" Localizable="false" />
<SharePoint:ScriptLink language="javascript" name="~sitecollection/SitePages/scripts/bootstrap.min.js" OnDemand="true" runat="server" Localizable="false" />

The page using this master page is not loading the scripts.

I checked using FireBug and there is no error like 404 or aborted (in red color) or anything.

Page source does have references to the script like this:

<script type="text/javascript">RegisterSod("~sitecollection/sitepages/scripts/jquery-1.9.1.min.js", "\u002fsitepages\u002fscripts\u002fjquery-1.9.1.min.js");</script>
<script type="text/javascript">RegisterSod("~sitecollection/sitepages/scripts/bootstrap.min.js", "\u002fsitepages\u002fscripts\u002fbootstrap.min.js");</script>

What can I try?

5

The problem is with the use of OnDemand=true. If you set that property than you are asking Sharepoint to only load the scripts on demand i.e. when you explicitly call them. This techique is used to reduce the amount of scripts loaded at page load. When applied script can be requested to execute by using SP.SOD.execute or SP.SOD.executeFunc methods.

.master master page:

<SharePoint:ScriptLink language="javascript" name="SP.Search.js" OnDemand="true"      runat="server" Localizable="false">
 </SharePoint:ScriptLink>

Page that require the script:

$("#MySearchButton").click(function () {
        SP.SOD.executeFunc('SP.Search.js', 'Microsoft.SharePoint.Client.Search.Query', SetSearchSettings);
});

Here SP.SOD.executeFunc ensures that the SP.Search.js file that contains the Microsoft.SharePoint.Client.Search.Query function is loaded and then runs the specified callback function SetSearchSettings - See more at: http://onlinecoder.blogspot.com/2014/03/loading-javascript-libraries-only-when.html#sthash.moZYqYMM.dpuf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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