views:

143

answers:

5

I have developed one of my modules using Dojo. Its gone really well and I have done a lot of custom plugins and server support in Dojo to allow AJAX calls, RPC + SMD communication with my server.

However, now that I am getting onto the user side of things, I am seeing that jQuery has some really nice already built plugins. Do you think it is possible to support both JS libraries realistically without it being a massive problem?

What kind of integration can I achieve? Does anyone have experience in this?

I have probably written somewhere in the region of 30k lines in Dojo for my Administration panel...

+1  A: 

When using 2 libraries (both of which, I'm sure - were designed to be used by themselves) you have 2 main worries:

  1. That one library will effect the other.
  2. That having a dependency on 2 libraries will bloat your pages.

In this case, I would bet that #1 is not going to happen. Although #2 is still a concern.

Gabriel McAdams
The only way that I think Dojo woul affect jQuery is because of the dojo.parse(). I wouldn't be that concerned about this. I am very concerned about number 2 and bloating.
Laykes
I'd be surprised if different libraries can co-operate in enhancing the same element (event-handlers, styles, modifying content, etc) or even the same branch of the DOM tree. I'd also be on guard for problems if using event-delegation - `live()` in jQuery.
Sean Hogan
+5  A: 

jQuery is very good about not messing with the prototypes of built in javascript objects (unlike Prototype), this allows it to be used with other libraries quite easily.

A source of potential conflict is jQuery's use of $ as a shortcut for jQuery. I'm not a dojo user, but if this conflicts with dojo in some way, there are instructions addressing this.

That said, I think you'd be better off looking at these jquery plugins and rewriting them and porting them to dojo. I'm sure the dojo community would appreciate it, and it would give you experience. It'd also make your application a little slimmer in the waist area.

Edit: I've noticed a couple answers trivializing the download speed of adding an additional library. I'd take this with a grain of salt.

As developers we tend to see only the extra 10ms it takes to download the library over localhost, or from our development server on a 100 Mbit LAN. The download speed is not so trivial from California to Virginia, or especially from USA to Europe. Additionally, it adds further burden on your client's javascript engine. If they are using a 1-2 year old good computer with Safari or Chrome, this would be negligible, but if they're on IE, FF2, or some versions of FF3 the difference can be severe, or at least measurable.

hobodave
Thanks hobodave. I think that you are probably right. I do absolutely love Dojo, I just don't know why I chose it at first when it appears like the standard library these days that everyone uses is jQuery. Its a little dishearteneing, however, the Dojo community is absolutely awesome and #dojo is a great place to be!
Laykes
I think Dojo is just underrated and that jQuery has more momentum (which means more plugins, which means more users, which means more ...). I still primarily use jQuery for that reason, but wouldn't worry about using Dojo!
Iain Collins
It's not the namespacing of JS libraries that would be the main issue. It's the fact that they both manipulate the same DOM. When mixing libraries I would expect the reduction in development time to be matched by the increased effort in testing and maintenance.
Sean Hogan
Very good point Sean.
hobodave
Happily, Dojo does not use $. Dojo is also very careful about avoiding Object prototypes and global names, so the two libraries should not have conflicts in that area, and I have seen the libraries used together on various occasions. Of course, exactly what each plugin or library extension is different, so there is always a chance of some conflict in logic, even within the same library.
peller
@hobodave As much as I like efficiency I do disagree with the load time being significant. At most it's a one time affair and it should be sub second one-time operation, even on a 3G connection from a mobile to a server half way around the world. The impact of inevitable inefficient image compression (including rendering time for something like a PNG with an alpha channel vs JS load time) utterly eclipses the issues relating to overhead caused by using an additional JS framework.
Iain Collins
A: 

I have used Prototype, jQuery, and ExtJS on several projects (for various reasons) and almost always use jQuery and ExtJS together. One way to limit trouble would be to avoid mixing libraries in any given page - keep Admin page to dojo and new pages to jQuery - but what fun would that be? :-)

I find few problems when integrating jQuery and ExtJS. I pick a framework for classes/objects/inheritance (I use ExtJS) and stick to it. Then, I use ExtJS to create most widgets and I use jQuery for low-level DOM manipulation and simple widgets. Again, I cannot recall running into conflicts when using two libraries, but FireBug is a good tool to uncover suspected causes of such conflicts.

Upper Stage
A: 

Most of the popular JS libraries can be scoped to their own global shortcuts. JQuery can be set to not initialize the $ variable. JQuery aside, I hear that Dojo and Prototype can work together without conflicting.

Regardless of what combination of JS libraries you decide to use, the best way to get information on compatibility issues is to hit the mailing lists relevant to the JS libs you'll be using with each other.

  1. http://docs.jquery.com/Using_jQuery_with_Other_Libraries
  2. http://www.dev411.com/blog/2006/06/13/dojo-and-prototype-together
Damien Wilson
A: 

Query.noConflict() makes for fairly easy interoperability because you can redefine $. As hobodave draws attention to, Prototype is lousy in this regard (because you can't easily just redefine $ with Prototype). I am not sure but I think Dojo doesn't have any issues of it's own and plays nicely with others out of the box (please someone correct me if that's not true).

The biggest problem I've had is the number of "must have" libraries written in specific frameworks, such as for things like sophisticated graphing that would be non-trivial to implement from scratch.

Bloat is bad, but compared to image sizes JS script sizes are of negligible concern (because it's so small and connections are so fast and it's only on first page load if you get your caching right, it's almost a non issue). I'd say maintiainablity being more of a worry, and it's a matter of deciding if you want that must-have-plugin that you don't have the time or inclination to reinvent in whatever framework you are using.

Iain Collins