Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. WebWorker API > Hack 69. Connect to Shared Workers Simultaneously from Multi...

Hack 69. Connect to Shared Workers Simultaneously from Multiple Browser Windows

Dedicated web workers are directly associated with their respective spawning script, but shared web workers allow any number of browser window contexts to communicate with a single worker simultaneously. As you will see in this hack, shared workers implement a slightly different API, but overall the concepts are very much the same.

Just like dedicated workers, to create a shared web worker you pass a JavaScript filename to your Worker instance, except this time you use the SharedWorker object.

Unlike dedicated web workers, shared workers introduce the concept of a port object that must be designated along with the attached message event handler. After that, we call the port’s start() method.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint