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

And*_*erg 4 javascript web-worker requirejs js-amd

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

Rob*_*b W 7

在Web worker中,可以使用该importScripts函数加载其他脚本.RequireJS源代码显示还支持Web worker:

// 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);
Run Code Online (Sandbox Code Playgroud)

  • 在尝试它的过程中.也可以在requirejs文档中找到它.出于某种原因,我的搜索引擎没有把它拿起来:http://requirejs.org/docs/api.html#webworker (3认同)