Dynamic 如何通过CDN实现延迟加载,并在requireJS中使用动态查询参数?
我在这个问题上花的时间太长了。我很惊讶这是如此难以实现 工作 不起作用 错误:尚未为上下文加载模块名“googleLoader”:_ 也不起作用 网络错误:找不到404- 如果未使用异步插件,则在加载脚本之前,模块和从属模块将继续执行 不过,这并不起作用 ) 在本例中,return语句似乎没有等到anon函数解析后才执行Dynamic 如何通过CDN实现延迟加载,并在requireJS中使用动态查询参数?,dynamic,requirejs,Dynamic,Requirejs,我在这个问题上花的时间太长了。我很惊讶这是如此难以实现 工作 不起作用 错误:尚未为上下文加载模块名“googleLoader”:_ 也不起作用 网络错误:找不到404- 如果未使用异步插件,则在加载脚本之前,模块和从属模块将继续执行 不过,这并不起作用 ) 在本例中,return语句似乎没有等到anon函数解析后才执行 define('mapAPI', ['googleLoader'], function (G) { // Google is good t
define('mapAPI',
['googleLoader'],
function (G) {
// Google is good to go
}
);
define('googleLoader',
['async!http://maps.googleapis.com/maps/api/js?sensor=true'],
function(){
return window.google.maps;
}
);
define('mapAPI',
['require'],
function (require) {
(function () {
require('googleLoader')
}());
}
);
define('googleLoader',
['async!http://maps.googleapis.com/maps/api/js?sensor=true'],
function(){
return window.google.maps;
}
);
define('mapAPI',
['googleLoader'],
function (G) {
// Google is good to go
}
);
define(
['require'],
function (require){
require(['async!http://maps.googleapis.com/maps/api/js?sensor=true']);
return window.google.maps; //undefined
}
);
define('googleLoader',
[],
function () {
var script = document.createElement("script");
script.src = 'http://maps.googleapis.com/maps/api/js?sensor=true&callback=gCB';
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
return (function load() {
if (window.google) {
var G = window.google;
return G;
}
else {
setTimeout(load, 50);
}
}());
}