我正在使用Google Javascript客户端API,我想知道以下两段代码之间的区别是:
//in the html file
<script src="https://apis.google.com/js/client.js?onload=gapiInit"></script>
//in a javscript file
gapiInit = function() {
alert("Loading the Libs!");
var numApisToLoad;
var callback = function(){
if(--numApisToLoad == 0) {
alert('APIs Ready!');
}
};
numApisToLoad = 1;
gapi.client.load('plus','v1',callback);
};
Run Code Online (Sandbox Code Playgroud)
还有这个..
<script>
// Asynchronously load the client library
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
Run Code Online (Sandbox Code Playgroud)
我在谷歌提供的各种示例中都看到过,Google Plus登录示例使用后者,而云端点示例使用前者.
他们只是两种做同样事情的方式吗?我使用它真的很重要吗?
developer.google.com中的示例
//端点 -
https://developers.google.com/appengine/docs/java/endpoints/consume_js
//加登录(似乎同时执行) -
https://developers.google.com/+/web/people/
//只是异步脚本.. …