requirejs可以通过http加载js吗

requirejs可以通过http加载js吗,
比如:require("http://api.baidu.com/map/1.2.js")

阅读 7.3k
1 个回答

支持的!
支持与否,为啥不自己试试呢?

但是不是你那样写的,要先配置。

require.config({
  paths:{
    'baiduapi':'http://api.baidu.com/map/1.2.js'
  }
});
//调用
require('baiduapi');

可以参考这里:
http://requirejs.org/docs/api.html#confi...

There may be times when you do want to reference a script directly and not conform to the "baseUrl + paths" rules for finding it. If a module ID has one of the following characteristics, the ID will not be passed through the "baseUrl + paths" configuration, and just be treated like a regular URL that is relative to the document:
Ends in ".js".
Starts with a "/".
Contains an URL protocol, like "http:" or "https:".

顺便推荐一下,我写的模块加载,实现原理和require,seajs之类的不一致。


https://github.com/donghanji/pm

也是支持url的方式加载模块的。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进