我尝试使用 requirejs 和异步插件加载适用于 JavaScript 的 Google API 客户端库:
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