Google AJAX CDN Libraries for jQuery

I have a page where I need SWFObject, jQuery, and the Google Maps API. I thought I could take advantage of using:

<script type="text/javascript" src="http://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script type="text/javascript">
    google.load("jquery", "1.4.1");
    google.load("swfobject", "2.2");
    google.load('maps', '2', {'callback': googleMapSetup });
</script>

But now I read somewhere (http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/ ) what I need to use

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

instead of $ (document) .ready () .. Is that true?

+3
source share
1 answer

There are two ways to use the Ajax library APIs.

First, you can just use Google to host your jQuery file:

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

Secondly, you can use it to perform asynchronous jQuery downloads, which you are talking about. If you do this, the template will look like this:

<script type="text/javascript" src="http://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script type="text/javascript">
  google.load("jquery", "1.4.2");
  google.load("swfobject", "2.2");
  google.load('maps', '2', {'callback': googleMapSetup });
  google.setOnLoadCallback(function() {
    $(function() {
      // Place init code here instead of $(document).ready()
    });
  });
</script>

, google.setOnLoadCallback(), , jQuery , jQuery , .

, jQuery , , Javascript, .

+4

Source: https://habr.com/ru/post/1735152/


All Articles