Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Just curious how others are handling their jquery related solutions. It's obviously very easy to add a Content Editor web part with a content link to a source file. That file could have your Jquery/javascript and CSS links. But then where do you put that file and what about your CSS?

Or, are you better off using sandboxed solutions and keeping things together in SiteAssets or Layouts? Well, I know that you're better off, but are you then keeping a content editor in your solution too?

There are a million ways to do this, just wanting to get a feel for what others are doing. I find myself using jquery more and more as people want dynamic solutions. It's better to use a Dataview or a Content Query when possible, but sometimes that adds more complexity as libraries like SPServices (Thanks Marc) have made bring back items quick and easy.

share|improve this question
    
You're welcome! –  Marc D Anderson May 27 '12 at 20:29

3 Answers 3

There are a number of ways to handle this, and which is best depends on your situation and requirements. If you want to use the files farm-wide, and deploying to layouts is an option for you(some places it is frowned upon), then by all means put it in the layouts. The advantage here is that updates happen in one place, and also your users cannot accidentally mess it up. If farm access is a problem, or you want to use jQuery only in a small number of site collections, you can put it in site assets or a custom document library. If you do this keep in mind you may have multiple places to support this file. By the way, the same concepts apply to your custom javascript files as well.

The other side of the coin is, how do you reference your javascript into your site pages? You could add a script link to the master page, or to any content page you need, but I think the best way is to use a custom action with a

Location=ScriptLink

This will load your files throughout the site, even dialogs. See Jan Tielens's post here for more info.

Bottom line, consider all options and do what makes the most sense for your project.

share|improve this answer
    
If you're doing a sandbox solution, layouts is not an option. You'll have to deploy to a doc lib. –  Derek Gusoff May 22 '12 at 14:45
    
I personally sandbox everything I can and then push additional files (CSS, additional JS) to SiteAssets. JQuery is added via scriptlink and that seems to work well. My main reason for starting this post was to see how others handled these types of situations. It seems I'm not too far off of the norm. –  CeeMoney May 22 '12 at 18:26
    
You can deploy jQuery through a module in your Visual Studio project and use the technique in Jan Tielens' post and it will work in the sandbox without having to separately deploy/manage jQuery in a document library. For more info, see this post: community.zevenseas.com/Blogs/Daniel/Lists/Posts/… –  Danny Jessee May 28 '12 at 13:03

There are lots of different, totally acceptable answers to this set of questions. jQuery is indeed now used ubiquitously, and many organizations are including it in their master pages.

The main thing is to be consistent. If you know that your users are going to use jQuery, that may influence your decisions. Be sure that all of your developers follow the same rules (governance, anyone?) and inform your users what the rules should be for them as well.

One possibility I don't see mentioned above is to reference script libraries from CDNs. It's not the right answer for everyone, but it may be for you.

I find that there's lots of discussion about performance when it comes to where to store and reference script files, but little empirical testing. Every environment is different, whether it be server performance, network topology, firewall configuration, load balancing, etc. Set things up in your environment and see what works best. _layouts, Document Libraries, CDNs, they all work, but you may see differences in your environment.

Hope this helps...

share|improve this answer

Have a look at thsi Codeplex Project, while it does not answer your Question , it seems to be nice for Development / In Place editing

share|improve this answer

Your Answer

 
discard

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.