www.webdeveloper.com
Results 1 to 6 of 6

Thread: Where does JQuery library reside?

  1. #1
    Join Date
    Dec 2013
    Posts
    21

    Where does JQuery library reside?

    I have admit that I am complete noob on all of this. I am trying to learn HTML5, Javascript, CSS, JQuery, etc.

    Does the JQuery library reside in the browser such that it executes the underlying JS from the library? Or is the JQ library code included in my server-side code when I publish? It sure makes more sense to me that it be only on the browser side to reduce the bandwidth.

    Sorry for the (probably ) stupid question but I just cannot seem to find an answer with all my searches.

  2. #2
    Join Date
    Oct 2013
    Posts
    609
    JQuery is client-side. That means that it's loaded with your HTML and other assets your page requires. It runs in the browser and not on the server.

    Bandwidth is another question entirely. Depending on which JQuery library you are calling it could be anywhere from 80 to 100+ kb of bandwidth. One of the advantages (in my mind) of calling a library from a central repository such as Google rather than hosting it on your site is that a user has probably been to another site using the same library. Therefore there's next to no bandwidth used since it gets loaded from their browser cache. The bandwidth used is whatever plugin script you have that uses the library.

    It's still another HTTP request no matter what. If the library is in cache it will load from there but the server still has to handle the request and send a response (304). If not in cache the file/library gets sent.

    Hope I didn't confuse you

  3. #3
    Join Date
    Dec 2013
    Posts
    21
    Thank you for the response Kevin! So wait...you mean the browser(client), when it parses a JQ request, may have to go out and ask an external server(JQuery.com0 to figure out the JQ? I was thinking the browser machine might have a local copy of the JQ library and just access it from the hard drive? No, you make complete sense. Just trying to understand what is going on. This is stuff I do not see when JQuery is explained. Thanks!

  4. #4
    Join Date
    Oct 2013
    Posts
    609
    If you are calling a JQuery library that a user does not have already in their browser cache it does download it from whereever your page calls it from. The browser does not come with JQuery preinstalled, but it will execute the code once downloaded and requested. JQuery is really a library of JavaScript that can be leveraged via plugins. So it acts somewhat like JavaScript in that it has to be called, loaded and executed.

    That being stated, having the JQuery file in the browser cache is almost like having it "built in" to the browser in that it doesn't have to be downloaded again. That's the reason for calling a library from a central repository like Google or JQuery.com. In all likelihood, your user has been to another site using the same library from either Google or JQuery and the file already is "built in" to their browser and doesn't have to be downloaded again. However if you host that library on your site the browser thinks it's a different library, even if it has the same filename, and downloads it again.

    A real world example: I have a photo gallery script on a couple of sites that uses HTML5, CSS3, and JQuery to present thumbnails and full-size photos in a really slick display. I call the JQuery library like this:
    Code:
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    But if I was hosting it on my site the code would look something like:
    Code:
    <script type="text/javascript" src="/assets/jquery.min.js"></script>
    To a browser those are 2 different files, even if the contained code is exactly the same. The link to googleapis would probably return a 304 to a browser and the file would load from cache. The "local" link would download the library from your site the first time a user hits a page needing it.

    More confusion, I suppose. Sorry for being so wordy...

  5. #5
    Join Date
    Dec 2013
    Posts
    21
    Interesting. And it makes complete sense, Kevin. Thank you for taking part of your Christmas Day to 'edumacate' me!

  6. #6
    Join Date
    Oct 2013
    Posts
    609
    I don't know how much of an "edumacation" was provided, but for what little there was you're welcome!

    Merry Christmas -- what's left of it!

    Kevin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles