I'm trying to rejigger my usage of web worker pooling to eliminate redundant server requests. In my existing solution, I'm loading workers pretty straightforwardly like this:
const worker = new Worker(`${src}?v=${version}`);
This happens N times for each worker pool. WebPack has no problem with this. But, in production, the N requests are superfluous, wasteful, and seem to introduce a little unnecessary latency. So, I'd like to get rid of them. To that end, I'm trying to load my worker code with a cached/debounced fetch() and feed the contents into the worker with a blob URL.
const worker = getBundleBlobURI(src).then(uri => {
return new Worker(uri);
});
Functionally, the worker is loading and operational. But locally, WebPack is now trying and failing to reconnect to ws://0.0.0.0:9999/ws on repeat, flooding the console with errors in the process.
How do make it stop?
My current workaround is essentially to use blobs only in staging + prod:
const isLocal = checkIfHostnameIsLocalhost(); // more or less
if (isLocal) {
const worker = new Worker(src);
} else {
const worker = getBundleBlobURI(src).then(uri => {
return new Worker(uri);
});
}
But, because I'm running slightly different code in dev environments, this comes with the risk of caching catastrophic regressions late (possibly even in production).