Step by Step: How to Add jQuery to a SharePoint 2010 Site Collection

Written by Denis Stadler on . Posted in jQuery

Both SharePoint 2010 editions (Server and Foundation) don’t provide a built-in feature that activates jQuery in a site collection.

Adding jQuery to SharePoint might not present a high interest for a traditional intranet portal solution, but if we use the Publishing feature, especially in web sites, jQuery could help us to improve our users’ experience.

The easiest way to add jQuery is, of course, to edit the master page and add the following lines of code, before the closing </head> tag:

<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js">
</script>

This code show his limitations if the computer of the user connecting to the SharePoint solution doesn’t have an active internet connection.

The Build of an Add-jQuery SharePoint Feature

A more elegant solution is to build a custom feature that injects the code in the “PlaceHolderAdditionalPageHead” content place holder, a content place holder that should exist on every SharePoint master page.

<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead"
runat="server"/>

To achieve this, I had initially to create a new SharePoint empty project using Visual Studio 2010.