Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

javascript - 没有单独的Javascript文件的网络工作者?(Web workers without a separate Javascript file?)

As far as I can tell, web workers need to be written in a separate JavaScript file, and called like this:

(据我所知,网络工作者需要用一个单独的JavaScript文件编写,并按如下方式调用:)

new Worker('longrunning.js')

I'm using the closure compiler to combine and minify all my JavaScript source code, and I'd rather not have to have my workers in separate files for distribution.

(我正在使用闭包编译器来合并和最小化我的所有JavaScript源代码,而我不必将我的工作人员放在单独的文件中进行分发。)

Is there some way to do this?

(有什么办法可以做到这一点?)

new Worker(function() {
    //Long-running work here
});

Given that first-class functions are so crucial to JavaScript, why does the standard way to do background work have to load a whole other JavaScript file from the web server?

(鉴于一流的功能对JavaScript至关重要,为什么进行后台工作的标准方法必须从Web服务器加载整个其他JavaScript文件?)

  ask by Ben Dilts translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...