4 ms·
The reason Web Workers do not have access to the DOM is because that would create a pandoras box of problems to solve, mostly revolving around concurrency and e
by benjoffe 16y ago
The reason Web Workers do not have access to the DOM is because that would create a pandoras box of problems to solve, mostly revolving around concurrency and efficiency.
If you have a loop where you are setting and reading dom values, then that loop should be protected from other scripts modifying the dom, and hence there's a good chance one thread will have to halt making the web-workers pointless.
What happens if a DOM object has JavaScript values attached to it (bad practice but can happen), does the web-worker have access to these? If not then each web-worker will need a separate dom representation possibly creating a huge overhead.
The best way to take advantage of multi core processors is to allow each thread to have largely their own local memory and pass messages asynchronously between them, most architectures short of this will suffer greatly.