File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Web Workers - Few Questions" Watch "Web Workers - Few Questions" New topic

Web Workers - Few Questions

Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 316

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

Joined: Jul 27, 2010
Posts: 25

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:

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 :)

I agree. Here's the link:
subject: Web Workers - Few Questions
It's not a secret anymore!