javascript HTML5 中的 Shared Worker 和 Worker 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6778360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between Shared Worker and Worker in HTML5?
提问by Tower
After reading this blog post: http://www.sitepoint.com/javascript-shared-web-workers-html5/
阅读这篇博文后:http: //www.sitepoint.com/javascript-shared-web-workers-html5/
I don't get it. What's the difference between a Worker
and a SharedWorker
?
我不明白。aWorker
和 a 和有SharedWorker
什么不一样?
采纳答案by nwellcome
Very basic distinction: a Worker
can only be accessed from the script that created it, a SharedWorker
can be accessed by any script that comes from the same domain.
非常基本的区别: aWorker
只能从创建它的脚本访问, aSharedWorker
可以被来自同一域的任何脚本访问。
回答by Raynos
SharedWorker's seem to have more functionality then Worker.
SharedWorker 的功能似乎比 Worker 多。
Among that functionality is :
该功能包括:
- A shared global scope. All
SharedWorker
instances share a single global scope.
- 共享的全局范围。所有
SharedWorker
实例共享一个全局范围。
W3C Spec:
W3C 规范:
WHATWG Spec:
WHATWG 规范:
回答by Martijn van Halen
To anyone considering using SharedWorker -- Apple removed support of SharedWorker
from WebKit in 2015. In their current roadmapthere is no plan for reimplementation. Support for Service Workersis currently under development for WebKit and offer similar capabilities (see here for comparisons).
对于任何考虑使用 SharedWorker 的人——AppleSharedWorker
在 2015 年取消了对WebKit 的支持。在他们当前的路线图中,没有重新实现的计划。目前正在为 WebKit 开发对Service Workers 的支持,并提供类似的功能(参见此处的比较)。
You can follow the development (aka Safari support) of ServiceWorkers in WebKit here.
您可以在此处关注 WebKit中ServiceWorkers的开发(又名 Safari 支持)。
回答by Mrchief
A shared worker can work with multiple connections. It posts messages to ports to allow communication between various scripts.
一个共享工作者可以使用多个连接。它将消息发布到端口以允许各种脚本之间进行通信。
A dedicated worker on the other hand is simply tied to its main connection and cannot post messages to other scripts (workers).
另一方面,一个专用的 worker 只是简单地绑定到它的主连接,并且不能将消息发布到其他脚本(worker)。