Does jQuery ship with SharePoint 2010? (and why you should be using an Ajax CDN)


NOTE: This was cross posted from here.

jQuery is one of the most popular javascript libraries used by ASP.NET developers.  In fact, jQuery ships with Visual Studio 2010.  It is in the “Scripts” folder of a new “ASP.NET Web Application” or “ASP.NET MVC 2 Web Application” project template.

Does jQuery ship with SharePoint 2010?  Short answer: No.  I see this asked (publicly and internally) a few times a month.  Long answer: You don’t need it to.  Just use it from the Microsoft Ajax CDN

Assuming you don’t have to build a solution on a closed network with no internet access, then one of the first things you should consider is to replace all the references in your code to local javascript files to CDN references.  By doing so you get the general benefit that all CDNs offer (not just Ajax CDNs) which is that you get directed to a server the is closer to you.  Also, since browsers cache files based on URL, referencing the CDN from all your code means that different web apps use the same version of the javascript file cached in the browser.  Last, but not least, it means less files you have to maintain on your own servers.

Here’s what a script reference to jQuery 1.4.2 looks like when it is local:

<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

Here’s what it looks like when referencing the CDN:

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script> 

So that’s how easy it is to reference jQuery from your SharePoint code.  However, as you can see, this applies way beyond just SharePoint programming.

-Marc

Comments (7)

  1. Nico says:

    Most of real world SharePoint implementation are for intranet, and I don't think many enterprise will be happy to include internet dependencies in their intranet…

  2. Josh Lyon says:

    @Nico — if you are using jQuery on an intranet implementation, then just move the jquery js into your hive and reference the file from there.

  3. Ken says:

    Is there anyway to suppress browser security messages when using CDN if the web page requires HTTPS?

  4. Brian says:

    Ken – there is a secure https version of the CDN too:

    ajax.googleapis.com/…/jquery.min.js

  5. BinaryJam says:

    It's not just about where to get things from, it's about picking a version and nailing it to the  mast.  Why do I as a dev need to worry about exactly how to include the library, customaction (script) additional page head, included in webparts.

    Then what about webpart s that need it and use a different version to the one I'm using.

    MS should just pick a version stick in the 14 hive (and 12 with an SP for 2007) and include it in pages, whether thats master page or delegate control, whichever.  Just pick it, patch it and let us all just start using it with impunity.

  6. BinaryJam says:

    It's not just about where to get things from, it's about picking a version and nailing it to the  mast.  Why do I as a dev need to worry about exactly how to include the library, customaction (script) additional page head, included in webparts.

    Then what about webpart s that need it and use a different version to the one I'm using.

    MS should just pick a version stick in the 14 hive (and 12 with an SP for 2007) and include it in pages, whether thats master page or delegate control, whichever.  Just pick it, patch it and let us all just start using it with impunity.

  7. Labhesh says:

    Hi, is it possiable to add the tab from server side.

    i want to see if i can add the dynamic tab to this javascript control