aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Web Workers - Few Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Web Workers - Few Questions" Watch "Web Workers - Few Questions" New topic
Author

Web Workers - Few Questions

Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

I understand that Web Workers allow running JavaScript in parallel on a web page, without blocking the user interface. I also understand that Web Workers don't have access to the DOM that means I cannot select any html element. Also, Web Workers do not have access to 'parent'.

I have two questions related to Web Workers:-

1. When will I normally use a Web Worker?
2. As per the Web Workers specification given by WHATWG,
workers are expected to be long-lived, have a high start-up performance cost, and a high per-instance memory cost.

Why will I want to use something like this on client-side and that too in parallel to another JavaScript?

I tried to understand the examples given in the specification but couldn't understand their value.


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Ido Green
author
Greenhorn

Joined: Jul 27, 2010
Posts: 25
Palak,

As for the first question: "When will I normally use a Web Worker?"
I gave some ideas in previous thread here on coderanch.
As for more 'real world example' please checkout: http://greenido.wordpress.com/2012/05/20/web-workers-and-big-data-a-real-world-example/

As for the 2nd question - Please think on web workers as a solution to do:
* Network to/from the server in the background
* Create one central component that manage your local storage.
This case is interesting because it can even be done with shared workers and give you ability to have one point of 'true' to all the instances of your web app (e.g. many windows, tabs that share the same 'thread').
* WebGL - you wish to run some complex matrix manipulation
and many many more :)

 
jQuery in Action, 2nd edition
 
subject: Web Workers - Few Questions