HTML and CSS Reference
In-Depth Information
To test the utility of web workers, all you need to do is
write some bad code. This function runs a loop several
million times and attempts to report progress to the
page every so often:
function kill_browser() {
var j = 0;
var n = 1e9;
var p = n/10;
for (var i=0;i<n;i++) {
if (j++ > p) { j=0; log(i); }
The page has two buttons: one that calls this function directly and one
that calls it via a web worker. Depending on how fast (or slow) your
machine is, you may need to adjust the n value to get the best effect.
Change the exponent (the number after the e ) either up or down if you
don't see the following behavior.
Start by calling kill_browser() directly by
clicking the button. Unfortunately, noth-
ing happens—not even the initial “Start-
ing” message. At this point you may find
that your browser won't respond to clicks.
The timestamp claims that only 3 seconds
have passed, but it stopped updating the
moment the button was clicked. Eventu-
ally, the browser recognizes the issue and
asks if you want to stop the script.
Search WWH ::

Custom Search