WebWorker support #130

wants to merge 3 commits into


None yet

3 participants


I created a plugin to load a module as a worker, and created a shim to enable curl to load scripts from inside a worker. The makefiles were updated to build a worker-specific version and add to the kitchen sink.

There isn't any detection for worker support right now and I'm not quite certain about the best way to implement that, or if that should be a concern of this code (and curl).

There are a few ways I thought of to do this:

  • The most obvious way (to me) would be to just require the file as normal in the worker plugin, perhaps using setTimeout to fake asynchronicity. This seems like a bad idea though—it might lock up the browser.
  • Alternatively, a Worker shim could be added, to return Worker, whether it's fake or real. Kind of the same as the above.
  • Do something with has!, loading a non-worker module instead if the browser doesn't support Workers. This seems most reasonable.

See #122 for more history.

@alanpearce alanpearce referenced this pull request Aug 21, 2012

WIP: WebWorker support #122


I've been using this for a while and can't see anything else that needs adding at the moment.

I definitely think that using has! will be the best solution for conditional worker usage, but from reading a discussion seems as if it's not quite ready for use with curl yet. Until then, it's not that hard to live without.


Hmm, I decided to try the CJSM loader with this. Definitely doesn't work, but I think I'll wait for it to stabilise before looking at it. I also tried the node.js style of assigning module.exports as a function, which doesn't work when inside a worker.

At least rvalue require works.


Hey @alanpearce!

Lots of other stuff bogging me down, atm. Looking forward to seeing what you've created and want WebWorker support sometime soon! Thanks for being patient. :)

-- John

@unscriptable unscriptable was assigned Sep 26, 2012

importScripts will load each script synchronously, somewhat defeating the benefits of AMD. Using XHR + eval would allow async loading.


Thanks for your suggestion @scothis. It's definitely a better idea than just using importScripts, however I thought about it when I started and went with the simplest solution just to get it working. Initially it didn't seem like a big deal given that importScripts only blocks the worker thread.

@unscriptable I see there is some XHR code in the text! plugin. I'd like to use this in worker shim without duplicate code, but I'm not quite sure how you would want this organised. Let me know what you think and I'll get on it when I have time. :)

@unscriptable unscriptable removed their assignment Jun 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment