1

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.

3 Answers 3

6

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?

4
  • 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
    Sep 2, 2009 at 18:58
  • 1
    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 docs.jquery.com/Plugins/Validation and it's an excellent plugin.
    – Steerpike
    Sep 2, 2009 at 19:01
  • +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. Sep 2, 2009 at 19:01
  • I retract my guess about the server/client issue ;) Sep 2, 2009 at 19:02
1

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

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.