4
我正在嘗試webworkers讓我的計算沉重的Javascript真正平行。不過,我有一個問題,所有的JavaScript文件都是AMD模塊。我可以在我的webworker中使用requirejs嗎?怎麼樣?我可以在webworker中加載AMD模塊嗎?
我正在嘗試webworkers讓我的計算沉重的Javascript真正平行。不過,我有一個問題,所有的JavaScript文件都是AMD模塊。我可以在我的webworker中使用requirejs嗎?怎麼樣?我可以在webworker中加載AMD模塊嗎?
在Web工作者中,其他腳本可以使用importScripts
function加載。該source code of RequireJS表明,網絡工作者也支持:
// 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);
所以,僅僅是明確的......第一我叫importScripts(「require.js」);並在下一行我確實需要([...],函數(...){...}); ? – 2012-07-09 21:46:21
而且,據推測,您還可以使用選項配置您的需求呼叫? – 2012-07-09 21:49:00
@AndrewEisenberg'requireJS'應該包含腳本(請參閱答案中的源代碼鏈接)。去嘗試它,並報告回來;) – 2012-07-09 21:58:07