Graphics & Compute

Web Workers

Probing…

Web Workers is a web platform capability in the Graphics & Compute category. Run scripts on background threads. Supported in Chromium 4+, Firefox 3.5+, and Safari 4+.

Try it

Loading demo…

Code

const worker = new Worker(url)
worker.onmessage = (e) => {
  if (e.data.progress) setProgress(e.data.progress)
  if (e.data.done) show(e.data.count)
}
worker.postMessage({ limit: 2_000_000 })

// inside the worker — heavy loop never blocks the UI:
self.onmessage = (e) => {
  let count = 0
  for (let n = 2; n <= e.data.limit; n++)
    if (isPrime(n)) count++
  self.postMessage({ done: true, count })
}

Browser support

Chromium
4
Firefox
3.5
Safari
4

Frequently asked questions

Which browsers support Web Workers?

Supported in Chromium 4+, Firefox 3.5+, and Safari 4+.

Does Web Workers require HTTPS?

No. Web Workers works without a secure context, though serving your site over HTTPS is always recommended.

What is Web Workers used for?

Run scripts on background threads.

Can I try Web Workers in my browser?

Yes. shwcs.net runs a live Web Workers demo that probes your current browser and lets you try the API. Everything runs locally — nothing is sent anywhere.

MDN reference ↗ Specification ↗