Google AJAX API, jQuery & google.load() vs $(function() {})

1.4k Views Asked by At

when i use google.load() to load jquery, what do i use in place of

$(function() {
 ... 
});

is ...

google.setOnLoadCallback(function() {
 ...
});

the same thing? this may be too slow if i am loading alot with google.load()?

then will

google.load("jquery", "1.3.2", {callback: docLoaded()});

run AFTER the whole document is loaded?

2

There are 2 best solutions below

2
On

I think you should be safe using $(function) still, since it will wait for google to load jQuery, it is after all a part of the document. Or am I wrong here?

I always use local versions anyway..Just feels safer, you know (:

edit: Just tested it, and it worked, just using the regular $(function)

0
On

Take a look here : Google Ajax Apis Playground

The way they do it is like this :

google.load("jquery", "1");

function OnLoad(){
  // some Jquery instructions
}

google.setOnLoadCallback(OnLoad);