How can I load Google API (UDS.JS) on demand (using jQuery)?

Tried this:

$('.link').click(function(e) {
 $.getScript('http://www.google.com/uds/api?file=uds.js&v=1.0', function() {        
  $('body').append('<p>GOOGLE API (UDS) is loaded</p>');
 });
 return false;
});

      

Yes, it loads the main "uds.js" file and then blocks the page by loading the locale's JS file ("default + en.I.js", see line # 48 in "uds.js").

workaround (@jsbin)

+1


a source to share


1 answer


If you want to dynamically load google libraries you should check out google autoloader: http://code.google.com/apis/ajax/documentation/#AutoLoading

This works very well, but be careful if you are using the autoloader wizard.

http://code.google.com/apis/ajax/documentation/autoloader-wizard.html



there is a bug for the c & p code that worked for me: http://code.google.com/p/google-ajax-apis/issues/detail?id=244

Also I found that for some google libraries, if I try to load scripts asynchronously (for example yours), if I omit some optional parameters (language, callback, etc. - even with an empty string), I see the behavior. which you see.

Edit: went and tested it. Your solution is here: http://pastie.org/486925

+2


a source







All Articles