This is the bocoup web log with posts from Al, Boaz, Rick, Sam, Nate, Nick & Pete. You should also make sure to checkout code.bocoup.com, where we keep the finished versions of ideas we kick around here.


Jun 18, 2010

Javascript Web Workers: Opera 10.6 Beta Supports SharedWorkers


While poking around the Web Worker API in the latest Opera Beta Release, I discovered that they had also implemented support for Shared Web Workers. If you’re not familiar with Shared Web Workers, have a look here. The basic premise is that a Shared Worker can have multiple connections made to one Worker.


Paraphrased from the specification for clarity:


[Instead of a single message processing function, workers can attach multiple event listeners, each one performing a quick check to see if it is relevant for the message. If multiple authors wanted to collaborate using a single port to communicate with a worker, it would allow for independent code instead of changes having to all be made to a single event handling function.]


So how about some code? In order to run the demo I’ve prepared, you’ll need Opera 10.6 Beta 1. Then hop over to Github and grab the Gist.


The comments will guide you through each step of the demo’s functionality.


Basic HTML page for running the test:

The HTML page called in the iframe:

The Renderer (that’s your browser window)

The SharedWorker


This demonstrates how we can connect two different pages to the same SharedWorker process, and track our connections to them from one persistent object variable. Very exciting!

*Edit*
In the time since this was originally published, Chrome,
Safari &
Opera now support complex JSON messages.



Comments:

2 Comments

  1. Posted June 18, 2010 at 9:34 am | Permalink

    For all other browsers (including IE8+), you can simulate shared workers by using the “storage” event and modifying properties on the sessionStorage object, which is shared across all views with the same origin, just like shared workers. However, you’ll need to listen to the event on the document instead of the document view in IE8 due to a bug.

  2. Rick Waldron
    Posted June 18, 2010 at 9:44 am | Permalink

    Thanks for the additional information, however it should be noted that a “simulated” worker thread or shared worker thread is never going to provide the same benefit that you with true parallel execution environment.

4 Trackbacks

  1. [...] Additionally, I discovered support for Shared Workers [...]

  2. [...] This post was mentioned on Twitter by Molly E. Holzschlag, Phred, Alistair MacDonald, rick waldron, Eli Grey and others. Eli Grey said: RT @rwaldron: New Blog! Opera 10.6 Beta supports SharedWorkers! Demo gists included: http://gul.ly/7l #javascript #opera #sharedwebworke … [...]

  3. [...] my excitement and haste upon discovering new SharedWorker() support in the Opera 10.60 Beta, I neglected to snoop around the window object of my two favorites, Chrome 5+ and FireFox 3.6+ [...]

  4. [...] Waldron has detailed the SharedWorker support that Opera has added in 10.6 beta (and has been available in Safari 5 and Chrome [...]




Please send your questions to this address or call Bocoup at 617-379-2752
This web page is proudly maintained by Bocoup and hosted by (mt) Media Temple
All code on this website is Open Source