This question has been asked and answered here and here. However, both threads are 18+ months old and things are evolving rapidly in the javascript world. So I'm asking again to get an up to date answer.
For our use we need a single background thread that will be running pretty regularly. It's for a rich editor and whenever the user edits, this background thread needs to recalculate the layout of the rich text.
It looks like Web Workers are the best approach. However, according to wikipedia "It is removed in newer Android browser versions".
Questions:
I would recommend WebWorkers as your first option.
True, they were removed from Android in 2.2, but were also re-added in 4.4 and are now supported by the latest version of all major platforms. See http://caniuse.com/webworkers to see in which version WebWorkers are available.
For browsers without support for WebWorkers I would recommend a fallback with postMessage()
or setTimeout()
, as detailed in Javascript - how to avoid blocking the browser while doing heavy work?