我可以在网络工程师中加载AMD模块吗?

时间:2012-07-09 21:06:31

标签: javascript requirejs web-worker js-amd

我正在尝试让网络工作者使我的计算量很大的Javascript真正并行。但是,我有一个问题,我的所有javascript文件都是AMD模块。我可以在网络工作者中使用requirejs吗?怎么样?

1 个答案:

答案 0 :(得分:7)

在Web worker中,可以使用importScripts function加载其他脚本。 source code of RequireJS表明Web工作者也受到支持:

// Line 23:
isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
// Line 1877:
} else if (isWebWorker) {
    //In a web worker, use importScripts. This is not a very
    //efficient use of importScripts, importScripts will block until
    //its script is downloaded and evaluated. However, if web workers
    //are in play, the expectation that a build has been done so that
    //only one script needs to be loaded anyway. This may need to be
    //reevaluated if other use cases become common.
    importScripts(url);