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