3

I'm working in SharePoint 2010 Designer to create a custom page layout. I've added a SharePointWebControls:ScriptLink control but am not sure what the path is to my jQuery library. It's uploaded to the root collection's Site Assets, in subfolders /js/jquery/jquery-1.6.2.min.js.

The absolute URL to it is http://vmdev195/SiteAssets/js/jquery/jquery-1.6.2.min.js. Is there a way to give a relative path to this file in the ScriptLink control? This way the page will work on different servers that have the same folder/file structure. Thanks

2 Answers 2

4

If you're working in SharePoint Designer, then you can use a plain old tag instead and reference the .js file anywhere you want:

<script language="javascript" type="text/javascript" src="/Scripts/jquery.SPServices-0.6.2.min.js"></script>

Any relative path will work, whether it's in _layouts, a Document Library, or an external CDN.

3
  • Thanks, Marc. That worked beautifully :) For some reason, I forgot that the client-side options are available in asp:Content areas. Plus, Designer allows you to pick the file and it'll generate the path automatically. Very nice.
    – Alex C
    Commented Aug 4, 2011 at 14:18
  • [update] caveat: For 2013 MDS enabled sites, script tags won't work, use RegisterSOD or ScriptLink.
    – Hugh Wood
    Commented May 22, 2014 at 16:13
  • They still work, don't they? I seem to remember using them just fine, but I could be mistaken. Commented May 22, 2014 at 22:10
5

Have you tried this?

<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<!-- ... -->

<SharePoint:ScriptLink runat="server" Name="/SiteAssets/js/jquery/jquery-1.6.2.min.js" Localizable="false" />
4
  • Thanks, omlin. I've seen the SharePoint:ScriptLink tag but couldn't figure out what the difference is between that and the SharePointWebControls:ScriptLink tag.
    – Alex C
    Commented Aug 4, 2011 at 10:27
  • That doesn't work; it throws this error, even though the file is there: Cannot make a cache safe URL for "1033//siteassets/global/js/jquery/jquery-1.6.2.min.js", file not found. Please verify that the file exists under the layouts directory. What does work is this: sensoft2000-sharepoint.blogspot.com/2009/09/…. Not the most convenient way to do it, but it works.
    – Alex C
    Commented Aug 4, 2011 at 10:50
  • 1
    Alex, I'm afraid you simply forget about Localizable="false" attribute.. That's why you're getting "1033" attached in front of the url. Commented Aug 5, 2011 at 7:43
  • 1
    For 2013 (v15) and current SharePoint Online (v16) you need to use a url token to get a site relative reference for the name property, like ~site/SiteAssets/js/jquery/jquery-1.11.1.min.js
    – John-M
    Commented Nov 13, 2014 at 18:00

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.