HTML and CSS Reference
In-Depth Information
FIguRE 10.1 Some browsers
will interrupt JavaScript that's
gone wild, and give you the
option to nuke it into space.
More worrying, though, are the much more subtle issues. Say
you've written the latest and greatest web application that does
the most amazing photo manipulation. You're using all the l33t
skills you learnt from this topic—canvas, storage, oline applica-
tions—but when it comes to adding a photo filter, it takes 30
seconds. It's not the 30 seconds that's the problem; it's the fact
that your user can't do anything in the browser for those 30 sec-
onds. What if your user changed her mind and wanted to cancel
the filter? Obviously this is a situation you want to avoid.
This scenario is perfect for a Web Worker because all the filter
processing can happen in the background, and the main brows-
ing window—and the rest of your web application—is left alone
to continue to be responsive to your visitor's requests.
Creating and working with workers
Yo u c a n t e s t f o r W e b W o r k e r s u p p o r t b y c h e c k i n g w h e t h e r o r
not the object is undefined:
if (typeof Worker != “undefined”) {
// do the jazzy stuff
}
Now that we know we've got support (Safari, Safari Mobile,
Chrome, Opera, Firefox, and IE10 all support Web Workers)
we can go about creating a new worker:
var worker = new Worker('my_worker.js');
A new worker object is fired up, reads in the my_worker.js
JavaScript file, and is now happily running and ready to be used.
 
Search WWH ::




Custom Search