2017-03-17 103 views
0

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

+0

我已经看到了。但我的问题是不同的。我的怀疑是明智的,而不是明智的概念。共享工作人员如何访问同一个域的所有脚本? – Vasi

+0

你好,我的问题是重复的,但答案是不同的。作为一名前端开发人员,我知道这个答案。但我无法理解你的建议,从堆栈溢出链接。你的链接有非常基本的信息。所以我提到了很多链接。在答案标签中查看我的答案,然后理解它。如果你不明白你自己在这个评论中与我联系。 – Vasi

回答

-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. 

共享工作者自己的功能。

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

参考链接,Workers document