Ido Green

author
+ Follow
since Jul 27, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
7
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ido Green

@Dave - today most modern browsers got 6-40 connections: http://www.browserscope.org/?category=network so I guess we are in a better shape :)
Nevertheless, you are right about the idea that you should control the number of workers and their network usage.
It sounds like you might have a memory leak...
So first I would check the current state of your web app by using Chrome devtools audit tab (or firebug similar option).
Then, you can take your current code that using COMET (on top of XHR) and port it into a worker. You should be fine with it running inside the worker for long-long time.
BTW, it might be good idea to write a 'unit test' that take just the code you wish to run in the worker and test it first on a regular page.
Sure thing!
I hope you will find it useful.
Ajax is 'Asynchronous JavaScript and XML' - Don't ask me why XML when 'everyone' is using JSON these days... :)
So to tune your question... I guess you wish to learn JavaScript and get better at it, right?

If this is the case here are two books that are excellent:
* JavaScript: The Definitive Guide by David Flanagan - http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996/
* JavaScript: The Good Parts by Douglas Crockford - http://www.amazon.com/dp/0596517742/
The book contain information around it :)
You will want to leverage Modernizr and do something like:


The main problem is what do you do in these older browsers...
and for that, you need to see what will be the right solution for your case so your site/web app will do 'graceful degradation' and the user won't suffer.
A novice JavaScript developer will be able to undersand this book.
The book's TOC compose from the different types of workers and how we might want to use them in each case.
There are examples for each chapter that you can learn from and the code itself is simple (IMHO).
However, I would not recommend it to someone that is 'just' starting to learn JavaScript since it's a book
around specific subject and there are many other features you will want to master before you reach to multi-thread programming ;)
This is a great question Pawan.
In the book you will find ideas and tips on when to use web workers in your sites/web apps.

There are many cases where it will be smart to off the 'load' some our main thread. Few examples:
* Complex mathematical calculations for security, webGL etc'.
* Make network requests - Ajax is good but think on cases where you want one point of 'sync' for your web apps.
* Access local storage - local storage is not async action! so the usage of web workers here make a lot of sense.
Sounds good!
Thank you for the links - I'll check them over the weekend.
I've only tested it on"Chrome for Android" and it is working great.
It should also work on mobile safari iOS 5.0+

The set of tests I used are from my book
and you can find them on github: http://greenido.github.com/Web-Workers-Examples-/

If you are using COMET over XHR I don't see why not...
Web workers contain a limited sets of features but XMLHttpRequest is one of them.
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 :)

Thank you Philip!
We got them on Chrome for android today... and very soon we are going to get this support: http://caniuse.com/#feat=webworkers on iOS and other mobile browsers.
I won't say you are paranoid because we've learn in the (short) history of the web that if 'something might break - it will' :)
IMHO, we don't have the same problem as in C because our JS run inside a sandbox in the browser. There are many limitation that the browser enforce us (=web developers) and we've made some progress in areas like CORS: https://mikewest.org/2011/10/content-security-policy-a-primer
It will be interesting to see what are the measurements that browsers will take to make sure this powerful feature won't be abuse.