Web Workers
Ran Wahle
Agenda
● What are web workers?
● Worker
● SharedWorker
What are web workers?
● A javascript object
● Should run in another thread
● Have different scope
● Can interact with the main js thread
Initialize and working with WebWorker
● Feature detect
● Spawn by calling the Worker() constructor
● Handle messaging
Messaging -code sample
Shared Workers
What is a shared worker?
One worker can serve many browsing contexts
Worker sends and receives messages through a port
SharedWorker Internals
Handle the “connect” event of the shared worker
Worker Vs. SharedWorker
WebWorker SharedWorker
Different scope Different scope
One / Many per context One / Many per many contextes
worker.postMessage worker.port.postMessage
self.onmessage = message => {...} Use onconnect
Summary
Workers can both makes our work faster, by parallelize our
work, and with SharedWorkers we may easily share one
worker instance between many view context, and easily
share state by that.
Demo code
https://github.com/ranwahle/jsil-webworkerDemo
Thank you
@ranwahle
ran.wahle@gmail.com
ranw@tikalk.com

Web workers