Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Shared Worker and Worker in HTML5?

After reading this blog post: http://www.sitepoint.com/javascript-shared-web-workers-html5/

I don't get it. What's the difference between a Worker and a SharedWorker?

like image 599
Tower Avatar asked Jul 21 '11 15:07

Tower


4 Answers

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.

like image 84
nwellcome Avatar answered Oct 31 '22 07:10

nwellcome


SharedWorker's seem to have more functionality then Worker.

Among that functionality is :

  • A shared global scope. All SharedWorker instances share a single global scope.

W3C Spec:

  • SharedWorker
  • Worker

WHATWG Spec:

  • SharedWorker
  • Worker
like image 44
Raynos Avatar answered Oct 31 '22 08:10

Raynos


To anyone considering using SharedWorker -- Apple removed support of SharedWorker from WebKit in 2015. In their current roadmap there is no plan for reimplementation. Support for Service Workers is currently under development for WebKit and offer similar capabilities (see here for comparisons).

You can follow the development (aka Safari support) of ServiceWorkers in WebKit here.

like image 16
Martijn van Halen Avatar answered Oct 31 '22 07:10

Martijn van Halen


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

like image 11
Mrchief Avatar answered Oct 31 '22 07:10

Mrchief