Skip navigation
Currently Being Moderated

How do I call the jquery library?

Jul 10, 2013 9:06 PM

I seem to have a hole in my knowledge about using jquery - I have a lot of jquery effects in my web page, and as I've installed some of them, it calls for loading a different version of jquery from ajax.googleapis.com. So now I've called jquery in to the page 3 times...like this: 

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>    

<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"type="text/javascript"></script>

 

I would have thought if I call in the latest version of jquery once, it will make all my jquery stuff work. But each plug in seems to need a different version of jquery to function and one of my jquery sliders isn't working. If I remove one of the scripts above, it WILL work, but then none of the other jquery effects will work!

 
Replies
  • Currently Being Moderated
    Jul 10, 2013 10:53 PM   in reply to idratherbeskiingonwombats

    If a script will work with jquery 1.4, it'll work with 1.8 (or 1.9 or 1.10). The latest would be the only one you need, but..... and this is probably important in your case...

     

    Not all jquery plugins or scripts "play well together", even if you add a "no conflict" declaration to your jquery script, and... using the remote scripts on Google servers you CANNOT do this.

     

    You can download your own jquery scripts here and run them locally, which gives you more flexibility.

     

    I have a really cool jquery menu on one site but it totally killed the ability to use Fancybox on the gallery page. The client wanted the menu more so I had to find another script for image display.

     

    Sometimes you have to choose what to keep and what to abandon with jquery.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2013 11:10 AM   in reply to idratherbeskiingonwombats

    jQuery's latest from their CDN works with just about every jQuery plugin I use.   In rare cases, when it doesn't, I add jQuery Migrate for older plugins or I try to find a more current ver of the plugin.

     

    <script src="http://code.jquery.com/jquery-latest.min.js"></script>

    <script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>

     

    I try to avoid any plugins that require jQuery 1.5 or earlier.

     

     

    Nancy O.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2013 10:20 PM   in reply to idratherbeskiingonwombats

    My personal preference is to use a "local" jquery file.
    Good example: Google was down for nearly four hours Monday in many parts of the world. I don't know if their "api" library was affected by that or not, but I'd hate for my jquery plugins to not work because someone else's server is down. If my server is down, no one's going to see the site anyway, but when it's back online everything will still work.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 13, 2013 9:40 AM   in reply to idratherbeskiingonwombats

    the thought of launching a website dependant on an ever changing code library freaks me out a little -  I can imagine them releasing a new version that accidentally messes everything up?

    It happens.  Fancybox stopped working for me when jQuery 1.8 came out.  But the Migrate script took care of that problem.   Also, CDN libraries are regularly updated to fix problems, often before we even notice there was a problem.  I don't lose sleep over this.

     

    CDN's make the web faster for everyone because, as you say, it's very likely that the end user already has the latest script in their cache.

     

    The reason your page works is because 1.8 is listed last.  You should be able to remove the duplicate scripts above it and it should still work.  Give it a try.

     

    Nancy O.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 13, 2013 5:26 PM   in reply to Nancy O.

    For those reasons the best approach is to load the CDN version when available, and if unavailable load up a local version. That way you get the best performance with CDN, and in the worst case scenario (CDN down) it just loads up your local version.

     

    Example code (html5 boilerplate taken as a reference):

     

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points