Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I would like to include js file from different location that it's now. Currently in master page code it looks as below:

<SharePoint:ScriptLink ID="ScriptLink1" language="javascript" name="Company/Scripts/myJsfile.js" Localizable="false" runat="server"/> 

and it works fine.

But what I'd like to do is to change current location of this javascript file. Target location of this .js file is a shared location (" \v-share\share\javascript ").

Is there any way to include this .js file from shared location in sharepoint master page ? Or is there any possibility to include .js file from location different than /_layouts/.. path (e.g. "C:\Users\Desktop\myJsfile.js")?

I would be very thankful for your help, because this case is very importan for me.

share|improve this question
    
Conrado: you can't register javascript file with links other that http(s)://. Actually, you could wrap the actual location of the javascript with a custom handler that will server the javascript over http, but it does not seems to be a best practice to me. If you don't want javascript to be stored in SharePoint, create a web application somewhere that will server the JS files. A bit like CDNs do. –  Steve B Jun 22 '12 at 14:53
    
And how I should define calling javascript file then? Like this: 1. <pre><SharePoint:ScriptLink ID="ScriptLink1" language="javascript" name=http(s)://Company/Scripts/myJsfile.js Localizable="false" runat="server"/><code> or 2. <script src=http(s)://Company/Scripts/myJsfile.js type="text/javascript"> </script> –  Conrado Jun 25 '12 at 7:29
add comment

2 Answers 2

Why don't you Store your js files in Style Library of Site Collection's root web. In such way it can be easily accessed and versioned in case of updates. See below

<SharePoint:ScriptLink ID="ScriptLink1" Name="<% $SPUrl:~SiteCollection/Style Library/Core Styles/jquery.js%>" runat="server" />"

If you can deploy to _layouts (i.e. not restricted to sandbox) and you anticipate needing these libraries across many site collections, I would deploy them to a folder within _layouts. Generally, it's good practice when deploying into _layouts to deploy to a subdirectory within _layouts, something like "_layouts/MYIVO"

<SharePoint:ScriptLink ID="ScriptLink1" Name="~SiteCollection/_layouts/MYIVO/Scripts/something.js" runat="server" />

share|improve this answer
    
Hey Falak, I'm using the link below to include my custom js file in a user control and it works fine, but NOT with an application page! Do we include js in an application page the same way or is it different? <SharePoint:ScriptLink ID="JsToAspx" runat="server" Name="(Path to the js file stored in _layouts)"></SharePoint:ScriptLink> Thanks in advance! –  Eliya Amanoeel Apr 30 '13 at 8:32
1  
Eliya, please see my updated response! –  Falak Mahmood Apr 30 '13 at 9:12
add comment

You will want to keep it in SharePoint. Putting it on your local c drive will not resolve for other users. Typically people will load it into the specific SharePoint site if it is local, or into the Layouts directory if its globally accessed.

share|improve this answer
    
But the problem is that this .js file needs to be in shared location. SSIS package from other server updates data in the js file (the second server has also access to this shared location and it updates javascript every hour). –  Conrado Jun 22 '12 at 14:26
    
Why is an SSIS package updating your js file every hour?!?!? You will have all kind of problems with caching and could have multiple versions of the js file executing all of the time. –  Mike Oryszak Jun 22 '12 at 14:28
    
I mean the package updates some variables only. But my issue is how to include a javascript file from shared location ? –  Conrado Jun 22 '12 at 14:32
    
I don't recommend this but can you move your shared location inside the layouts folder? –  Vardhaman Deshpande Jun 23 '12 at 13:13
    
It would be the easiest solution, but unfortunatelly it's not possible. –  Conrado Jun 25 '12 at 7:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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