javascript - Can I load AMD modules inside a webworker? - Stack Overflow

I am trying out webworkers for making my putationally heavy Javascript truly parallel.However, I have

I am trying out webworkers for making my putationally heavy Javascript truly parallel. However, I have a problem in that all of my javascript files are AMD modules. Can I use requirejs inside of my webworker? How?

I am trying out webworkers for making my putationally heavy Javascript truly parallel. However, I have a problem in that all of my javascript files are AMD modules. Can I use requirejs inside of my webworker? How?

Share Improve this question asked Jul 9, 2012 at 21:06 Andrew EisenbergAndrew Eisenberg 28.8k9 gold badges97 silver badges151 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

In Web workers, other scripts can be loaded using the importScripts function. The source code of RequireJS shows that Web workers are also supported:

// 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 bee mon.
    importScripts(url);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745596914a4635171.html

相关推荐

  • javascript - Can I load AMD modules inside a webworker? - Stack Overflow

    I am trying out webworkers for making my putationally heavy Javascript truly parallel.However, I have

    12小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信