Best practices for using multiple Javascript libraries on the same page?

javascript

Solution

Quite simply, don't do it. You'll have headaches with:

- Inconsistent code in your application ($('element') vs $('#element'))

- Possible conflicting libraries (Date.prototype.toJSON() is often defined in libs)

- Additional overhead for your users to download, thus worse user experience

- More documentation to keep track of, thus larger learning curve for new devs

- More code to keep updated and secure

- More time spent figuring out which library you want to use for what.

If you have some specific need that a different library addresses, pull the pieces of that library as needed. It'll save you way more time than it takes to extract what you need.

Problem

I have thought hard about what library would be best, but any library "X" would be missing a certain feature from library "Y". What are peoples' thoughts on using mutliple JavaScript libraries simultaneously?

Original source