5 ms·
It's impossible to use web workers across domains or while using non aliased cdns. Which can start to feel really restrictive.
by Kequc 11y ago
It's impossible to use web workers across domains or while using non aliased cdns. Which can start to feel really restrictive.
- DiThi 11y agoI got over that limitation by converting the code to a data URL, like this: var blob = new Blob([worker_code_string], {type: 'application/javascript'}); var worker_uri = (window.URL || window.webkitURL).createObjectURL(blob); var worker = new Worker(worker_uri); The path to the scripts imported with importScript() must be absolute, though. I add the path by modifying worker_code_string. Alternatively they can be fetched and prepended to the code string (or passed in the array of Blob()).
- Kequc 11y agoI was reading about that. It seems pretty strange that these heavy security restrictions on origin are in place but you can create a worker from a string.
- hippich 11y agoin my project HashcashIO[1] i get around that using iframe and loading main script for same domain. while restrictions exist, i believe it is easier to get around them (basically write code in secure fashion) rather than trying to break work into junks in the main thread. Although, depending on task i see cases where chunkify.js will be useful, since i myself used this idea, granted with adhoc implementation instead of using well defined library. [1] https://hashcash.io/ https://hashcash.io/