Web Workers and drive by CPU nabbing

Web workers are a great part of the html5 specification. They let you run a javascript program in a separate process; so that complex tasks can be done in the background without blocking nice, fluffy, user interactions with the page. Better still, if multiple web workers are run and multiple CPUs are available then they get scheduled across all the processor - multi-core javascript enables whole new avenues of complex (and awesome) code to be written and deliver a great experience.

....you can probably sense the but coming.....but - this means any page you navigate to, any link you click, any random website with funny pictures of cats on, has unfettered access to your CPU. While you browse worldsfunniestcats.com, it could be using your electricity to generate BitCoins for itself, or crack passwords.

To prove a point, below is a page that spawns a few web workers and sets them, continuously, generating prime numbers. Open up the page in a modern browser and check out your task manager (closing the page kill the web workers):

Update: It doesn't max-out the CPU in Opera...why? Because apparently Opera is so fast that it can handle the workload without breaking a sweat!

Update 2: Apparently IE10 can hack it too, looks like firefox and chrome are trailing on this..... there's a sentence I never thought I'd write.....

Update 3: On further investigation, it looks like Opera's performance is a combination of running the script at great speed AND some kind of limits on web workers, either in terms of number or CPU usage. I can't comment on IE10's performance as I don't have a windows 7 laptop..... if anyone is listening at microsoft..... *hint* *hint* :)



I'll admit that I'm slightly obsessed with zoomooz.js, it's a cross-browser (excluding IE) nice zoom plugin for jQuery. And although it has some issues with scrolling it's a top-notch plugin in my books. To showcase it's greatness I made a mock-up of a picture gallery*:

*if any of the pictures are yours let me know and I'll acknowledge you here.

The polaroid effect is CSS based, with a bit of javascript to fit the pictures. The random distribution uses CSS3 transforms (random rotation with a slight translation). ZooMooz.js then does the rest!

Geek Bootnote: The page uses @font-face and html5 data attributes to keep track of the ordering, the juicy javascript can be found here (script.js)

Update: A good intro on Zoomooz.js can be found here.