“This specification defines
an API for running scripts in the background
independently of any user interface scripts.”
“This allows for long-running scripts
that are not interrupted by scripts
that respond to clicks or other user interactions,
and allows long tasks to be executed without yielding
to keep the page responsive.”
Blocking the windows single thread
Using a Web Worker
Limited access to features
navigator object
location object (read-only)
XMLHttpRquest
setTimeout() and co.
Application Cache
Importing external scripts using importScripts()
Spawning other Web Workers
DON'T have access to
DOM (it's not thread-safe)
window object
document object
parent object
var worker = new SharedWorker('jsworker.js'); worker.port.addEventListener('message', function(e) { alert(e.data); }); worker.port.start();
worker.port.postMessage('Hi Slave!');
self.addEventListener('connect', function (event) { var port = event.ports[0];
port.addEventListener('message', function (e) { port.postMessage('Hi Master!'); });
port.start(); });
WIFI Password Cracking in the browser :-)
var slowSquare = function (n) {
var i = 0;
while (++i < n * n) {}
return i;
};
// Create a job
var p = new Parallel(100000);
// Spawn our slow function
p.spawn(slowSquare).then(yourCallback);