0

我不得不看共享工作者的例子。但我无法确定工人与共享工人之间的区别。共享工作者示例https://github.com/mdn/simple-shared-worker。谁能解释一下?

4

1 回答 1

-1

Worker 和 SharedWorker 工作流程如下。

此图有助于理解 Worker 和 SharedWorker 的工作流程和常见行为

Worker 和 SharedWorker 的区别

Worker 和 Shared Worker 之间的类似功能。

   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 拥有自己的功能。

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

参考链接,Workers 文档

于 2017-03-20T10:43:54.280 回答