views:

116

answers:

3

I am working on a server-side framework.

Here and there I have been adding hand-crafted javascript to do things on the client side. However this is becoming more and more painful and from what I heard I think jQuery can be of help.

The issue is that as this is essentially server side stuff, I don't want to obligate my users (assuming there will be any :) to use jQuery.

So the question is, how good is jQuery at coexisting with other popular javascript libraries? Will it hijack global names and events for its own purposes or is it a relatively respectful & coexisting dude.

+5  A: 

jquery has a noconflict option which helps with using it with other libraries.

You can also compare how much it pollutes the global namespace against other libraries here

I'm also not sure what you're actually asking, as you discuss adding javascript client side enhancements but then go on to say that it will mostly be 'server side stuff'. Which is it? Mostly client or mostly server?

Steerpike
interesting stuff. everything i'm doing is server side stuff, but there are things like ajax that are inherently also client side and things like validation that are best addressed in both sides.
flybywire
In that case, the jQuery ajax support is very good and simple - nothing spectacular but it's certainly better than rolling your own. Validation is very easy with the validation plugin http://docs.jquery.com/Plugins/Validation and it's an excellent plugin.
Steerpike
+1 This is pretty much exactly what x-x has asked for. I believe x-x might be building some kind of interface that allows users to insert their own javascript, which could result in a concern about library conflicts. The "server-side" probably just refers to x-x's actual server implemented code as opposed to user edited code.
Alexis Abril
I retract my guess about the server/client issue ;)
Alexis Abril
+1  A: 

The generally accepted principal with jQuery is scope your access to it within an anonymous function. This prevents namespace pollution. The pattern looks like:

// anonymous function that takes the jquery $ object (aka window.jQuery)
(function($) {
    $(document).ready(function() {
        // jQuery code here, call functions, etc

    });
})(jQuery.noConflict()); // removes $ from window scope, returns the jQuery object

See more: http://docs.jquery.com/Core/jQuery.noConflict

marshall_law
A: 

jQuery has two global identifiers: jQuery and $

You can change that to one identifier by using jQuery.noConflict(), and then the only global is jQuery.

Mike Blandford