SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to add jQuery and SPServices.

I added the following code:

<SharePoint:ScriptLink runat="server" Name="/Style%20Library/Scripts/jquery-1.7.2.min.js" Localizable="false"></SharePoint:ScriptLink>
<SharePoint:ScriptLink runat="server" Name="/Style%20Library/Scripts/jquery.SPServices-0.7.1a.js" Localizable="false"></SharePoint:ScriptLink>

to the v4.master at the bottom of the tag. I added both files to the root site's Style Library.

Everything was working fine on some sub sites. However, sometimes I got the following error:

Cannot make a cache safe URL for "/style%20library/scripts/jquery-1.7.2.min.js", file not found. Please verify that the file exists under the layouts directory. 

Where should I be putting these javascript files?

share|improve this question
up vote 11 down vote accepted

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/MyCompanyOrMyProduct" to avoid file naming conflicts. Deploying to _layouts will make longer term maintenance/upgrades easier if these libraries are being used across site collections. If you needed localizable copies of these files, you'd deploy them to the appropriate LCID folder under _layouts (for example _layouts/1033/MyCompanyOrProduct), but this doesn't sound like it will be needed in this case.

In this case, you could bypass the script link control all together, but it can add some value (like versioning), so it's probably worthwhile using <ScriptLink> to reference it from within the _layouts folder. You reference them in this way (without specifying _layouts path - the script link assumes _layouts by default):

<SharePoint:ScriptLink runat="server" Name="/MyCompanyOrProduct/jquery-1.7.2.min.js" Localizable="false"></SharePoint:ScriptLink>
<SharePoint:ScriptLink runat="server" Name="/MyCompanyOrProduct/jquery.SPServices-0.7.1a.js" Localizable="false"></SharePoint:ScriptLink>

If you make "localizable" versions of your scripts, and you use the for getting the scripts onto the page, be sure to set the Localizable="true" for your .

If you are constrained to the Sandbox, the Style Library is the correct location.

If you are going to keep them in the Style Library can try referencing the scripts using the ~sitecollection replacement token (generally Style Library is only provisioned at the root site within a site collection). You might be getting the errors described if you are in a subsite and the scripts are deployed to the root site of the site collection. For example:

<SharePoint:ScriptLink runat="server" Name="~sitecollection/Style%20Library/Scripts/jquery-1.7.2.min.js" Localizable="false"></SharePoint:ScriptLink>
<SharePoint:ScriptLink runat="server" Name="~sitecollection/Style%20Library/Scripts/jquery.SPServices-0.7.1a.js" Localizable="false"></SharePoint:ScriptLink>

I normally try these solutions out before posting, but don't have a VM handy at the moment.

You can also check out some other answers on this same topic here. Note: this question could be flagged as duplicate and closed. See: Where do you deploy scripts that are loaded in a masterpage? and this one from a few years ago, but still relevant: CSS Files in _Layouts or Document Library?

share|improve this answer
This worked, thanks! – Brandon Mar 30 '12 at 17:09

Your Answer


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.