1

There are a multitude of examples where jQuery libraries and plugins are used in SharePoint 2010 and 2013 solutions.

There are problems with this approach because multiple versions of jQuery can be available in various locations on the server (when deployed) and in various sites where jQuery is imported as a point solution. In some scenarios the paths to jQuery are directly specifying a jQuery version e.g. /_layouts/mySolution/scripts/jQuery_v_1.11.1.js

What is a good strategy to manage jQuery libraries so that they are deployed once to the Farm and not imported into every solution that is deployed?

  • You can deploy your files on Layouts folder in this case. Whats the issue with this? – Aanchal Sep 22 '14 at 13:39
  • @Aanchal the issue is that some solutions deploy the .js files locally to that solution whereas others deploy to the layouts folder itself. This results in two different versions of the .js files and potential problems when upgrading. When you are in an enterprise scenario and there are external vendors building solutions it's better to indicate to them that they need to use the existing versions of the jQuery libraries that are already deployed. – motionpotion Sep 22 '14 at 16:38
  • @motionpotion - communication and process are the key here. You can't really stop site admins from putting jQuery directly on their sites if they want to. Your best bet is communication and a clear, understandable process. The thing about going rogue with putting files on the site is that it's easy. Your solution should be easy as well, or they won't follow it. – Derek Gusoff Sep 22 '14 at 16:47
1

There are a number of ways to handle this, but here is one:

Create a solution package that deploys the files directly to _layouts. Put each version in a separate folder, for example _layouts/jQuery/1.11.1/ and so on so you can introduce new versions without breaking solutions built on older versions.

As far as referencing jQuery in your pages, you can add the script tags in the master page if you like, but I prefer a CustomAction ScriptLink. This approach decouples the scripts from the master pages and allows you to expose jQuery, or not, using the Feature framework. Thus when changing to a new version of jQuery you don't have to modify the master page - just turn off the old jQuery feature and turn on the new one.

Many organizations have the problem of power users adding their own JS libraries into their sites using Script Editor or Content Editor web parts. Unless you want to go around policing your farm, there's not much you can do about that except communicating to your teams that the libraries are already available on the farm.

TL;DR

Put it in a Feature

0

The best way I have found to do this is to just go ahead and load them into your masterpage. Use this link here in the head:

<SharePoint:ScriptLink language="javascript" name="MyJquery.js" defer="true" runat="server"/>

The script link tag will always point to the /_LAYOUTS/1033 folder so put your JQuery file there.

This line would load the page and then load the script file. If you set Defer=”false” then the instant the page loaded and hit that line the .js file would execute.

Using Defer=”False” is basically the same as loading the script with this method. But with this method below you can specify a location other that LAYOUTS/1033 if you wanted to.

<script type=’text/javascript’ src=”/_layouts/1033/myjs.js”></script>

SOURCE

  • The disadvantage here though is that then it locks other users into using potentially old versions and need to resort to side loading jQuery to use a different version. – Eric Alexander Sep 22 '14 at 17:12
  • This is true. You will ahve to update as needed, but you do not have to worry about calling the basic liraries in your web parts. SPServices and the JQuery library is usually all I put into the master. The UI and other JQuery add-ons I load within the web parts. – lazoDev Sep 22 '14 at 17:20

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.