SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what's the best way to utilize a library?

    Hello,

    I am going to start working with jQuery's library and I was just wondering...can I place the library in a "central" location on my computer and have all the websites I write point to the same copy of the library? Or, do I have to put a copy of the library in the "local" folder of each website?

    In other words, could I have the jQuery library located at var/www/jquery-1.2.6.js, and then have websites in locations like this...var/www/website1/index.html, var/www/website2/index.html, and so on, that point to the same .js file. Or do I need to place a copy of jquery-1.2.6.js in the website1 directory, and the website2 directory, etc...

    I know this is a REALLY dumb question. But, I am asking it anyway.

    Thanks in advance for your advice.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    I see no reason why you couldn't use a single source location. Except if you want to use AJAX, then you'll might run into a "same domain" restriction problem.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Google make a copy of all the major JavaScript/Ajax libraries available that you can call from their site so as to save your having to have your own copy. If everyone uses those then there is no overhead for your site with people having to download the library when they visit your site because chances are they already downloaded the library from Google when they visited someone else's site earlier so that it is already on their computer.

    See http://code.google.com/apis/ajaxlibs/
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Enthusiast stakes's Avatar
    Join Date
    Sep 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sometimes use googles hosted version of jQuery, but i also have a central folder for all my plugins/libraries, not just for javascript. In my httpdconf i have an alias setup so all projects have access to these files:

    Alias /js/jquery/ /var/www/jquery

    Now I can access all my jQuery plugins and code from both:

    domain1.com/js/jquery

    aswell as

    domian2.com/js/jquery

    (Obviously aslong as they are on the same server)
    webcloud.se - Articles on web development

  5. #5
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for these answers!

    I will explore the AJAX same-domain issue because that is exactly the reason I want to use jQuery.

    I will also try the Google-hosted option. In the end, that sounds like it may be the best option. Since I am new to using a Javascript Library, I wanted to download the library and use it locally, so I could look at it, and really get a feel for how they are done. But using a remotely hosted library, when it comes time to publish my site, sounds very attractive. (How does the Google-hosted option get around the AJAX same-domain issue, or does it?)

    Thanks for the suggestion of using an alias in the config file. I will play with that as well, as I try to work locally at first...

    Thanks again.

  6. #6
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's best not to use scripts hosted on a third-party site. If their site goes down, your site will stop working properly. Also, not having absolute control over what's in the script files linked into your pages can pose a security risk.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    I'm not sure if Google are in much danger of going down, but what was said is a good piece of awareness to have when you're dealing with externally hosted libraries.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    I'm not sure if Google are in much danger of going down....
    I've had AdSense failures freeze my page loads before.

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    It would depend on which is more important to you.

    - the slight chance that the Google libraries may be unavailable and that your script therefore doesn't work, or
    - the large number of people who never wait for your page to finish loading because of the relatively long time that the script library takes to download to their computer.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    - the large number of people who never wait for your page to finish loading because of the relatively long time that the script library takes to download to their computer.
    Jquery is only 20k in size (minified and gzipped). That's not going to cause much of a lag


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
  •