JS library like JQuery can be linked directly from other site (e.g. google). Usually I use

<script type="text/javascript" src="/js/jQuery.min.js"></script>

But I can use

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

or similar.

I like to take full control over my site, so I use the first way. But using google or other host has some advantage (i.e. decreased latency, increased parallelism, better caching). Both have advantage and disadvantage. What should I use? What you use and why?

Please let me know your opinion.

Thank you


Please note that JQuery is just an example, it could be any JS library.

Written by Sadi

Accepted Answer

I think that it depends on the audience of your website.

If your site is public facing and people are going to be accessing it primarily or exclusively from the internet then you are going to benefit from lower bandwidth utilization, faster responses and caching benefits since the likelihood of the file having been previously referenced and loaded from another site is high.

If your site is internal for an intranet you may run into issues of people do not have internet access but you're also going to be wasting bandwidth since you're sending everyone out over the internet to fetch a file you could host locally.

Written by MyItchyChin
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki