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