Reputation: 559
I cannot import any libraries into my javascript web worker using importScripts(). When I import my own separate javascript files it works fine but when I try and import a separate library such as jquery or easeljs it gives my the error: Uncaught ReferenceError: document is not defined
however it clearly is correctly defined after i have continuously checked it. Anybody know what is wrong. Thank you.
Upvotes: 2
Views: 3147
Reputation: 6075
The reason it's that the webworkers can't do a refer to the DOM, they can only communicate through messages to the caller script. jQuery does an explicit reference to the DOM, so you can't use it in your webworker. I suggest you to have a look at this blog post from John Resig, the jQuery creator, about WebWorkers: http://ejohn.org/blog/web-workers/
Upvotes: 3
Reputation: 5226
Web Workers have very limited access to DOM objects and methods, and are completely unable to access the global document
object, which is required by both jQuery and easeljs.
I can't say for easel, but for jQuery there is a port of 1.6.3 which is compiled without the web worker-unsafe code. It can be found here.
Upvotes: 2