Opened 9 years ago

Closed 5 years ago

#11750 closed enhancement (fixed)

[CLA][patch] Support for Dojo in WebWorkers

Reported by: Sébastien Le Ray Owned by: dylan
Priority: blocker Milestone: 1.10
Component: Loader Version: 1.5
Keywords: Cc:
Blocked By: Blocking:


This tickets follows a discussion on the dojo-interest mailing list.

It would be nice to be able to use dojo inside WebWorkers? for all non-DOM operations (mainly XMLHttpRequest processing and all dojo.lang stuff).

I wrote a quick & dirty hostenv that provides what may be needed for that. Sadly, I did not find any documentation about the rules to follow, so I hope it will be fine.

We also need to look at dojo._base.xhr since it depends on dojo._base.query (which is needed for formToObject) even if we are not in a browser env. This prevents dojo.xhr to load since query relies on DOM elements (document or window) to be present.

Attachments (2)

hostenv_worker.js (3.5 KB) - added by Sébastien Le Ray 9 years ago.
Hostenv to have working dojo.require & dojo._base.lang. Adapted from hostenv_browser
Webworker.patch (5.1 KB) - added by simpo 6 years ago.
Fixed dojo/request issue

Download all attachments as: .zip

Change History (18)

Changed 9 years ago by Sébastien Le Ray

Attachment: hostenv_worker.js added

Hostenv to have working dojo.require & dojo._base.lang. Adapted from hostenv_browser

comment:1 Changed 8 years ago by Chris Mitchell

Owner: anonymous deleted

comment:2 Changed 8 years ago by Mike Stoddart

Any updates on this ticket?

comment:3 Changed 7 years ago by bill

Milestone: tbdfuture

Marking milestone future since there's no owner.

comment:4 Changed 7 years ago by j105rob

Can we get an owner? Or should I just put up any patches? I really need to have this working ASAP. Thanks!

comment:5 Changed 7 years ago by bill

j105rob - definitely put up your patches and then write a comment back here; I'll try to find an owner.

comment:6 Changed 6 years ago by simpo

Not sure if this is helpful but I did write something that does this in v1.8 (see: Dojo Webworker). Am happy for any of the Dojo people out there to re-use it, break it, better it, ...etc. The component handles workers; creating the worker, loading dojo into it, loading the file you request into it and then handling console messages, emitting messages from the worker, ...etc.

The diff file (Diff File) details some small additions to the dojo.js and adds an extra configWebworker.js file to go in the dojo/_base directory (in the same vain as the one for Node and Rhino). I don't know the procedure for making official contributions to the Dojo project (ie. supplying patch suggestions).

I used it extensively and it seems to work fine in all the situations I've tested it. I don't think it breaks anything else either. Although, it is possible it breaks in situations I've not thought of!

Last edited 6 years ago by simpo (previous) (diff)

comment:7 Changed 6 years ago by bill

Owner: set to dylan
Status: newassigned

Actually I'm not sure who this should be assigned to. Dylan, can you assign this to someone?

comment:8 Changed 6 years ago by dylan

Milestone: future1.10

If we can verify that this patch works with trunk, I'll land this for 1.10 as soon as 1.9 ships.

comment:9 Changed 6 years ago by simpo

I've added a new patch which works with v1.9. There were a few changes in v1.9 that seemed to break the original patch.

Passing the path for dojo packages to the worker script is a bit tricky. I'm using dojoConfig.baseUrl as it seems like best way to have a unified dojoConfig between the browser page dojo and worker dojo. Since the path is relative to the actual worker file (rather than the current webpage) it can mess-up relative paths if you are not careful.

I've got rid the 'global' variable in the dojo loader. This was because the loader now has it's own variable with the same name and also because assigning it to a variable called 'window' seems like a better idea.

Dojo 1.9 is now detecting the correct local from navigator (if not already supplied). Whilst, the navigator object is available in workers, it is not a fully implemented. Neither navigator.language or navigator.userLanguage are available. Hence, I had to work around this.

Also, I could not get dojo/request working as it fails on the empty plugin (dojo/request/default!). You can use dojo/request/xhr directly though; this seems to work perfectly. I'm sure there must be a simple way to fix this.

Edit: Fixed the dojo/request issue, too long looking at I think and missed the obvious. Should now be able to use dojo/request directly. Have replaced the patch with a new one.

Last edited 6 years ago by simpo (previous) (diff)

Changed 6 years ago by simpo

Attachment: Webworker.patch added

Fixed dojo/request issue

comment:10 Changed 5 years ago by dylan

@simpo, can you please submit a CLA?

comment:11 Changed 5 years ago by dylan

Put into a branch at

See my TODOs in there... it would really help if we had a test case to verify that it works. Also see my notes, I'm curious what we can do to make this approach more "AMD-ish" if possible.

And as noted before, definitely need a CLA before I can take this further.

comment:12 Changed 5 years ago by dylan

Summary: Support for Dojo in WebWorkers[CLA][patch] Support for Dojo in WebWorkers

comment:14 Changed 5 years ago by dylan

Revised pull request at

Looks like this is currently blocked on review by Bryan Forbes and/or Rawld Gill

comment:15 Changed 5 years ago by dylan

Component: GeneralLoader
Priority: highblocker

comment:16 Changed 5 years ago by ben hockey <neonstalwart@…>

Resolution: fixed
Status: assignedclosed

In 205416f41cc00d0391a019faac9f59c2aec51a87/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.