Web Workers
- main thread : where browser runs script, processes user events, painting, garbage collection
- worker threads: where a web worker runs code in parallel to thread that spawned it
- data is only copied [thread safe]
- have own event loops
- no DOM access, no access to
window
, not all web APIs are available
- uses
self
to access worker scope
Shared Workers
- a
Worker
can only be accessed from script that created it,
- a
SharedWorker
can be accessed by any script that comes from the same domain (different windows, iframes, workers.)
- uses an explicit
port
object to communicate
Service Workers
- act as proxy servers between webapp, browser and network (when available)
- used to create offline webapps, executing code based on if network is available.
- allow access to push notifications and background sync APIs