I'm developing a project with multithreading. For this I spawn 8 web workers, all with the same source code. These are spawned as follows:
var workers = [];
for (var i = 0; i < 8; i++) {
workers.push(new Worker('worker.js'));
}
But this requires the worker.js
file to be downloaded 8 times. Is there any way I can require the source file just once, and then re-use it?
Bonus question: is there any way to do this for importScripts
in the workers. Cause every worker is importing the same script now.