SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2013
    Location
    RI, USA
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    basic jquery script question

    I am adding a Git-based contact form w captcha on my bootstrap3 site; I'm not that averse on adding scripts and plugins yet.

    Before the closing body tag I currently have
    Code:
    <script src="https://code.jquery.com/jquery.js"></script>
    The code example for the contact form has
    Code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    Is this more or less the same jquery.js asset just with a different address, so I should replace mine? Or is the latter specific to my form, and I should keep both? Many thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2013
    Location
    RI, USA
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am thinking this references the ajax library for the captcha, and that I should keep both scripts.?.

  3. #3
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Don't keep both scripts.
    You should only include jQuery once per page.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,260
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    AFAIK the first will get the latest stable release version (which may or may not be what other code needs), and the second gets a specific version.

    If someting breaks because of incompatibility you can either include the version it needs or figure out what differences caused the problem(s) and modify the code.

    But as Pullo mentioned, you should not use more than one version per page.

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Mittineague View Post
    AFAIK the first will get the latest stable release version (which may or may not be what other code needs), and the second gets a specific version.
    Exactly.

    This:

    Code:
    <script src="https://code.jquery.com/jquery.js"></script>
    will pull the latest, non-minified version of the 1.x branch of jQuery from jQuery's own cdn.
    This is currently v1.11.0

    Whereas this:

    Code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    will pull in a minified version of jQuery v1.10.2 from Google's cdn.

    Notice the missing http:// at the begining of the url.
    This will cause things to break if you test locally, but has advantages when used on a server (namely the browser will use the page's protocol to try to obtain the file. On non-secure pages, http. On secure pages, https).

    In your case I would use a specific, minified version.
    Here is an interesting link on why it is best to include jQuery from Google's cdn: http://stackoverflow.com/questions/2...cdn-for-jquery

    HTH

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2013
    Location
    RI, USA
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I was interested in the difference btwn the 2 as well, so these answers are very helpful.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •