views:

56

answers:

4

Take a case, I want to use multiple javascript libraries into one page like jquery, mootools, scriptalous.

Is it a good idea? Should I do ths?

+1  A: 

You would want to use noConflict Mode. Like this : http://api.jquery.com/jQuery.noConflict/

As far as "Should you do this?".. I would say no. Outside of conflicts having multiple frameworks means longer load time.

Tyler
+2  A: 

Is it a good idea? Should I do ths?

No and no.

There are cases when using multiple libraries is necessary - e.g. when using a lot of legacy code that needs library A, and other parts use library B - but even though plugins like jQuery's noConflict can take some of the pain away, getting them to work together is usually hard.

There are also massive internal arguments against using several DOM handling libraries at once, because of the way those libraries deal with DOM objects internally. User Bobince once wrote an excellent post about this, sadly I can't find it right nowl.

If you have no compelling need to use multiple libraries, stick with one.

Pekka
+1  A: 

What happens If I combine multiple Javascript Libraries in a page?

The simple answer: it depends.

Technically, if each library properly "namespaces" its functions (and the namespaces don't clash), doesn't declare any global functions, and don't override/augment any native object prototypes, they could live together. In reality, however, there is very likely to be a clash (for instance, many libraries define their own $() function).

Find the library that best fits your needs and use that one.

Daniel Vandersluis
+1  A: 

It depends on the library. Libraries such as YUI, or jQuery use a strict system of namespaces that means that they can run happily together. E.g. The Module Pattern http://www.yuiblog.com/blog/2007/06/12/module-pattern/

However libraries that use a prototypal model, such as MooTools, or Prototype are much more complex. They use prototypal inheritance to modify native objects, such as Array, Number and String.

While this offers some very elegant solutions, and enables the library developers to "fix" some of the inherent problems with JavaScript, it does mean that they rarely play nicely together.

Also as the libraries may seem to run perfectly until a particular native is used in some obscure way, you can get intermittent, and very tricky to solve, bugs.

Matt