Adding SPServices js file in Master Page with Relative path (to site/subsite root)

Sep 11, 2010 at 2:47 PM

Problem: How do I reference .js files (or .css for that matter) in a site's customized with url's that are relative to the site's (or subsite) root folder?

                                                  ^-> "/appbin/" contains all my JS files.
                                                      Static directory, not a Document Library

All pages served for the above sub-site (sub-site-b) should reference files within the "../sub-site-b/" directory structure. but I have found no way to define the url within the <script> tag to say something like href="~SITEROOT/appbin/js/jQuery.SPServices.js".  I have seen the suggestion to use ~, ~SPSite, etc., but none of these have worked thus far...

The answer that I often get is "use a static and direct link to the files" (example: point to jQuery on Microsoft's CDN, Or create a site where some files will be hosted and point my links there)... but I'm working on a site that once complete, will be packaged as a site template and be made available to others groups within my organization.  I do not have server level privilages, and am developing/designing the site using pure JS, and Sharepoint Designer to create a few workflows, thus placing files on the server for all to use is not a viable path forward for me.  My preference would be to have the template include all necessary files for it and not rely on an external location to provide them.


Sep 11, 2010 at 3:19 PM


You can actually load the script files with script if you need to. (Yes, that sounds funny!) A better answer is to come up with one consistent location to store all of your js files.


Sep 11, 2010 at 3:59 PM

Thanks Marc for the quick response... so I guess there is no other way?



Sep 11, 2010 at 4:02 PM

There are always lots of ways. ;+) I'm not sure that you get any real benefit by distributing the js files all over the place, though.