Using multiple versions of jQuery on my website?

I do not know anything about Javascript, very new to this. I have two things working on my website individually but not together…! 1) A responsive slideshow that works with jQuery 1.8.3 and 2) A Iphone swipe function with TouchWipe which works with jQuery 1.2.6. Unfortunately when the slideshow works the Swipe function stops working since it is not compatable with later versions ( author has not updated the plug in ) . I came across this, that explains that it is possible to make two versions of jQuery work on the same webpage. I tried to make this work in my code by copying and pasting the code ( changed the versions.) . I am sure there is more to it than that and it is not working. Here is what I did… am I on the right track here? Thank you for you help…I am sorry if this is a silly question…

First part

<!-- load jquery 1.2.6 -->
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript">
var jquery_1_2_6 = $.noConflict(true);
</script>

Then changed the $ to jquery_1_2_6 in the code below…

jquery_1_2_6("#imagetouch").touchwipe({
wipeLeft: function() { window.location.href = $(".prev > a").attr("href"); },
wipeRight: function() { window.location.href = $(".next > a").attr("href"); },
min_move_x: 30,
min_move_y: 30
});

Then for the responsive slider…

<!-- load jQuery 1.8.3 -->
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript">
        var jquery_1_8_3 = $.noConflict(true);
        </script>

        <script>
         jquery_1_8_3(".rslides").responsiveSlides({
         speed: 1000,
         });
    </script>

You can only use one version of JQuery on a web page as most of the code remains unchanged from one version to the next.

The latest version that supports IE8 is version 1.11.3 so you should use that one unless you are trying to use antiquated code with it that is no longer supported - in which case you should look for a more up to date version of that code.

1 Like

@felgall felgall , thanks you very much for you reply. Sorry about my ignorance but just to make things clear. As I was looking for a solution I kept seeing jQuery’s noconflict mode. Are you saying this won’t work or I shouldn’t do that?

Yes the touchWipe code for Iphones is old and not updated recently. Are you saying I should abandon that or find an updated version instead of making it work with using multiple versions of jQuery on one page?

Thanks again…

No conflict mode is not about different versions of jQuery, but more about using the same names in different functions so the one won’t conflict with the other.

1 Like

I consider that the entire purpose of noConflict is to free up the global $ object for use by other frameworks. You’re still able to use the $ object within a document.ready wrapper without any trouble though.

jQuery.noConflict();
// $ out here is for other frameworks
jQuery(document).ready(function ($) {
    // $ in here is for jQuery
});

Remember also that loading two versions of a library is pretty inefficient. (Many would argue that even loading one of them is inefficient!) Ideally, find scripts that are reasonably up to date. There are quite a few swiping scripts around.

It is if you insist on loading a copy from your own site when your visitors most likely already have a copy or three cached from various common repositories that most other sites use.

Yes, it’a a fair point, although I’ve seen some people arguing that there are so many hosted versions out there that it’s not as likely as it seems that people will have it cached already.

Thank you @ralphm, @Mittineague @Paul_Wilkins and @felgall …for your time and your answers. I am off to finding a newer code for the swipe. Any suggestions on good swipe codes? :smile:

Slick handles touch quite nicely.

Assuming it’s a gallery swipe you are interested in, you could also use one with no dependencies: http://photoswipe.com/

1 Like

You could also use hammer.js and hook it up with the slider. The nice thing about hammer.js is it doesn’t have any dependencies on existing libraries. I would agree that it is best to stay away from abandoned code unless there is no other option given business constraints. Though I don’t know much about the state of TouchSwipe so won’t comment on it further in that respect.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.