Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web Workers - Few Questions

 
Palak Mathur
Ranch Hand
Posts: 342
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ido Green
author
Greenhorn
Posts: 25
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic