2017-03-17 133 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