SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
-
Nov 17, 2008, 21:36 #1
- 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.
-
Nov 17, 2008, 21:47 #2
- 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.
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Nov 17, 2008, 23:56 #3
- 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="^$">
-
Nov 18, 2008, 00:57 #4
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
-
Nov 18, 2008, 06:21 #5
- 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.
-
Nov 18, 2008, 09:00 #6
- 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.
-
Nov 18, 2008, 09:13 #7
- 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
-
Nov 18, 2008, 10:15 #8
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Nov 18, 2008, 13:09 #9
- 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="^$">
-
Nov 18, 2008, 13:57 #10
- Join Date
- Oct 2005
- Location
- London
- Posts
- 1,678
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks