Web workers


var worker = new Worker('worker.js')

worker.onmessage = function (message) {


Messages can be anything that can be serialized into JSON (objects, arrays, strings, numbers, booleans). See: structured clone


self.onmessage = function (message) {

self.postMessage({ msg: 'hello' })

Message data


bubbles: false
cancelBubble: false
cancelable: false
clipboardData: undefined
currentTarget: Worker
data: "Hello"             ← the data
defaultPrevented: false
eventPhase: 0
lastEventId: ""
origin: ""
ports: Array[0]
returnValue: true
source: null
srcElement: Worker
target: Worker
timeStamp: 1344821022383
type: "message"

These are the contents of message on onmessage.

0 Comments for this cheatsheet. Write yours!