gpt4 book ai didi

javascript - 我可以在 webworker 中加载 AMD 模块吗?

转载 作者:搜寻专家 更新时间:2023-11-01 05:25:09 25 4
gpt4 key购买 nike

我正在尝试使用 webworkers 使我的计算量大的 Javascript 真正并行。但是,我有一个问题,因为我所有的 javascript 文件都是 AMD 模块。我可以在我的 webworker 中使用 requirejs 吗?如何?

最佳答案

在 Web worker 中,可以使用 importScripts function 加载其他脚本. source code of 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);

关于javascript - 我可以在 webworker 中加载 AMD 模块吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11403161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com