我尝试使用requirejs和async插件加载Google APIs客户端JavaScript库:
require.config({
paths : {
async : '../lib/requirejs/async'
},
waitSeconds: 60
});
define('gapi', ['async!https://apis.google.com/js/client.js!callback'],
function(){
console.log('gapi loaded');
return gapi.client;
}
);
require(['gapi'], function(){
console.log("Callback");
console.log(gapi);
});
通常加载此库的方式是: 点击这里。
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
所有内容都在2秒内加载完毕,但我总是会遇到这个错误:
Uncaught Error: Load timeout for modules: async!https://apis.google.com/js/client.js!callback_unnormalized2,async!https://apis.google.com/js/client.js!callback
http://requirejs.org/docs/errors.html#timeout