WebWorkers are awesome! Unfortionately, Google Chrome doesn't support creating subworkers, here's the Chromium issue for it.
This polyfill provides this functionality to Chrome and any other browser that supports WebWorkers, but not subworkers. This functionality is implemented by creating all subworkers in the context of the main page and simulating the communication.
Using this is easy!
In the document hosting the WebWorkers, include the
subworkers.jsscript before any scripts that create WebWorkers.
In the code for any WebWorker that will have a subworker, you also need to include
That's it! WebWorkers now work the way you would expect!
- Install subworkers.js by running
npm install -s subworkers
- Import the library in all scripts
require('subworkers'); // CommonJS // or import 'subworkers'; // ES2015+
This project is released under the MIT License.