HTML and CSS Reference
In-Depth Information
imageData: imageData,
x: data.x
// self close
Notice also how photofilter.js , once it's done performing its
task, calls the close() method. This allows the worker to termi-
nate, since it's not required for use again.
Importing scripts and
libraries to your worker
Web Workers is very much about modularising a block of code
or functionality and running it in a stand-alone environment
(that is, the worker itself). Web Workers can also load external
JavaScript fi les and libraries via the importScripts method.
This is one of the few worker-specifi c methods. It accepts a list
of URLs and loads them into the worker synchronously. You can
load one script at a time, or you can load multiple scripts from
within the worker:
importScripts('prime.js', 'number_crunch.js',
¬ 'captain_crunch.js');
Each script is processed one at a time. The script must be on the
same origin as the worker—the same domain, cname, etc. The
worker then synchronously loads the JavaScript into itself, return-
ing to continue only once the script has finished processing.
Sharing a load with SharedWorkers
Another type of Web Worker is the SharedWorker , currently only
supported in Chrome and WebKit (rather than Safari). A shared
worker is pretty much like an average Web Worker except that
multiple documents can access the same single instance of
the worker. So this means that if you have several popups or
several iframes, all of those documents can access this single
shared worker and this single shared worker will serve all of
those documents.
Search WWH ::

Custom Search