What would be the best approach in using/including jQuery in Office 365? Should I just use google CDN or is it possible to deploy the jQuery file to the server?

Is there any good articles/resources available on this topic?

6 Answers 6


Sandbox mode implies you'll have to do it all at a site level. Personally I'd be going with a CDN link, and additionally I'd be checking to see if it's already been loaded elsewhere in the page - useful in the case of a jquery-dependent webpart which may be included two or three times in a page:


Of course, if the solution you're building is for general release, you'll want to include the files so that it'll still work in secured intranets which don't have a way to hit the CDN - in which case deploy to a library such as the style library (a common target for JQuery)


The most preferred location to add JQuery is the "Site Asserts" library which exists in SharePoint Online - Office 365 site. Quick Steps to create a solution for this

  1. Create a Empty Solution in Visual Studio 2010 and deploy it as sandbox.
  2. Create a Folder called JQuery.
  3. In this Folder add an new Module. You would notice you get a new Elements.xml and a txt file. You can delete the txt file.
  4. Add the JQuery library in the "JQuery" folder.
  5. Next edit the Elements.xml to add the "URL" parameter, where the JQuery library will be deployed. You will notice that Elements.xml will now contain the Module element for JQuery.

Open elements.xml file and Change the following

  1. Edit Module Name - Add some name "JqueryModule"

  2. Add URL property to Module, something like URL ="Site Asserts"

  3. In File tag add Type=”GhostableInLibrary”

Thats it!

Reference http://preachingsharepoint.blogspot.ca/2012/05/add-jquery-to-office-365-sharepoint.html


You have deploy jquery library to document library like style library and refer it from there. You can use CDN too if you prefer to do so.


I posted a blog artlice about adding a jQuery reference to Office365 which is essentially the same as a sandbox solution here http://blog.ianchivers.com/2012/04/add-jquery-to-office365-solutions.html.

Becuase of the restrictions on Sharepoint 2010 Sandboxed solutions it's essential to be able to write functional code client side, as you are very restricted on what you can do on the server.

Writing Javascript can be extremely labourious without the assistance of some helper libraries like jQuery, and adding javascript links and code is even a challenge in a sandboxed solution.

Here's a cool way of adding jQuery code to Office365 or Sharepoint Online sandboxed solutions.

protected override void RenderContents(HtmlTextWriter writer)  
            StringBuilder js = new StringBuilder();  

            js.AppendLine(" alert('hello world!');");  


            writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");  
            writer.AddAttribute(HtmlTextWriterAttribute.Src, "//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");  

            writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");  

There's also a post about on how to add a stylesheet to a page from a Sharepoint 2010 sandbox webpart: http://blog.ianchivers.com/2011/11/add-stylesheet-to-page-from-sharepoint.html


Check out this article on ITUnity: Managing JavaScript References in Office 365

enter image description here


You can add jQuery files in Style library through module and access it from style library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.