NullPointer NullPointer - 1 month ago 11
jQuery Question

Is it better to reference jQuery file include through jQuery CDN?

Is it better to reference

jQuery
file inclusion through
jQuery CDN
for better performance?

Like

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>


Or

Is it better to reference stored
jQuery
file in our project?

Like

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


As
jQuery CDN
link handles caching, Does it improve performance more than
jQuery
file included from our project?

Answer

First variant. Because google has best world-wide servers.

  • Decreased Latency
  • Increased parallelism
  • Better caching

The best way to initiate jQuery engine:

<script src="http://www.google.com/jsapi"></script>
<script>
  google.load("jquery", "1.10.2");

  google.setOnLoadCallback(function() {
  // Place init code here instead of $(document).ready()
 });
</script>

Here is a good article about this:

http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/