什么是共享工作者?工人与共享工人之间有何不同?

时间:2017-03-17 08:03:03

标签: javascript web-worker shared-worker

我不得不看共享工作者的例子。但我无法确定工人与共享工人之间的差异。 共享工作者示例https://github.com/mdn/simple-shared-worker。 任何人都可以解释一下吗?

1 个答案:

答案 0 :(得分:-1)

下面给出了Worker和SharedWorker的工作流程。

This image helps to understand working flow and common behavior of Worker and SharedWorker

Difference between Worker and SharedWorker

工人和共享工作者之间的类似功能。

   The Worker works in another thread. So it's not affecting the main thread. So that time users can scroll, view the page without blocking.

1. Worker can't access DOM elements from the web page.
2. Worker can't access global variables and functions from the web page.
3. Worker can't call alert() function.
4. Objects such as window, parent, document can't be accessed inside the worker.

工人拥有自己的特色。

Workers life time between page creates and closure. Once the page creates the new workers will be created. View first image that blog diagram says about Wokers.

共享工作者自己的功能。

Shared Worker连接来自同一域的所有网页。查看博客图表中关于Wokers vs Shared Workers的第二张图片。

参考链接,Workers document