I know that web workers cant access the dom directly. But would it be a bad idea to do something like this:
var doc = $(document);
var worker = new Worker("worker.js");
worker.postMessage({ cmd: 'doDomStuff', data: doc });
Do you see any downsides with this peice of code?
Any tips/comments are much appreciated.
update: Just to be clear: I only want to getdata from the DOM, not set any new values or manipulate the DOM in any way.
I don't see any reason why you can't do this, but this could lead to issues when you are trying to manipulate the same element in the worker and in the main js code at the same time.
You would need to add some mutex locking to your code.
Sorry scratch the above...
Workers do NOT have access to:
The DOM (it's not thread-safe)
The window object
The document object
The parent object
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With