2

I am working on a project that has two versions of jQuery loaded on a page (versions 1.5.1 and 1.7.2). The 1.5 version is for an implementation of jsTree, and the 1.7 version is for the latest version of jqGrid.

I understand the performance implications of downloading two versions of jQuery and also the potential for name collisions, but has anyone run into a situation like this and are there inherent problems that the page will encounter because of this.

Currently, the site runs fine and I'm not noticing any significant issues that could be caused by different versions of jQuery on the page. But I cannot quickly remove one version or the other, as it seems to cause one or the other control (the tree or the grid) to crash.

I need to remove one version of jQuery. I am looking for advice on what potentials problems to expect with two versions of jQuery on the page and advice on how to go about removing one reference. And, if there is anyone that thinks it's fine to have both versions, any thoughts on why I should just leave well enough alone.

Thanks in advance!

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
  • As far as I know, in the same scope JS overwrites the latest copy. Intead, I would look for a way to deal with the conflict there by renaming one copy if there's no chance I can make jsTree plugin work with the latest jQuery version. – inhan May 21 '12 at 18:38
  • 3
    On the [jsTree demo page](http://www.jstree.com/demo), the author is already using jQuery v1.6.1. It's entirely possible that his plugin will work perfectly fine in the newest version of jQuery. My advice would be to upgrade jsTree to the latest version, and use jQuery 1.7.2 only. – Robert Harvey May 21 '12 at 18:40

3 Answers3

3

You can definitely run two versions of jQuery on one web page. The only downside is the additional http request.

However, making 1.5 code run in 1.7 isn't very difficult. Get rid of the 1.5 and make sure that 1.7 is above all of the plugins that require jquery and see what breaks. Post here or in the jQuery forums for support on fixing those small issues.

The most likely change you will have to make is changing a few .attr() calls to .prop() due to a change in 1.6.

Edit: It would also be wise to follow Robert Harvey's advice and upgrade jsTree to the latest version.

Kevin B
  • 94,570
  • 16
  • 163
  • 180
2

Other than the overhead of having multiple libraries, I'm not aware of anything major you'd run into. If you do run into an issue, jQuery.noConflict() may help you resolve it

This SO thread deals with your topic. How do I run different versions of jQuery on the same page?

Community
  • 1
  • 1
1

Yes it can handle two versions of jquery.....In the second version declare a variable as $.noConflict(true). And use the declared variable in place of $ used in the jquery code. Please check the below code : This code is used after the declaration of second versions of jquery:

<script type="text/javascript">

var jQuery_1_9_1 = $.noConflict(true); function pageLoad(sender, args) {

        var $ddl = jQuery_1_9_1("select[name$=drpClassCode]");
        var $ddl1 = jQuery_1_9_1("select[name$=drpSubContractors]");
        $ddl.select2();
        $ddl1.select2();

        $ddl.bind("change keyup", function () {
            $ddl.fadeIn("slow");


        });

        $ddl.bind("change keyup", function () {
            $ddl1.fadeIn("slow");


        });
    }