What's The Reason To Include Scripts With Two Different Calls?
Solution 1:
They reason html5 Boilerplate includes the script that way is because it attempts to "load jQuery library from local server if it's not reachable from Google CDN." =)
Solution 2:
<scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
This will attempt to load the protocol-less version of the jQuery library
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.6.2.min.js"><\/script>')</script>
This will load the local version of the jQuery library if the google-hosted version was not loaded properly (unreachable, site is down, etc), hence the window.jQuery
check. If window.jQuery
is not true
then it will execute the document.write
Solution 3:
Loading jQuery from the Google CDN can be much faster than loading it from your local server and it can be cached so the user might already have a cached copy of it from another website.
The check is make sure that it got loaded, otherwise if it failed, load it from the local server.
Solution 4:
Yes, it's checking if jQuery is loaded or not, if not then loading it from own server.
//
only is used to make it compatible with both HTTP and HTTPS.
Solution 5:
The reason is failback. The first line of code
<scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
Pull the jQuery library from the Google CDN as you said. Then this next line:
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.6.2.min.js"><\/script>')</script>
Will verify that jQuery library was loaded (from the Google CDN), if not, then retrieve a local copy of jQuery.
Post a Comment for "What's The Reason To Include Scripts With Two Different Calls?"