Load worker scripts from other domain (CORS)
wclr opened this issue · 3 comments
I tried to upload all app scripts to CDN and load from there, but the problem appeared with workerized scripts.
DOMException: Failed to construct 'Worker': Script at 'http://.../d60d5e58103bdf59892b.worker.js' cannot be accessed from origin...
I know that workers can not be initialized from CORS scripts, but any idea is it possible to solve/workaround?
Oh I found there is inlne
option that solves is.
@developit
I also found that there is a worker-plugin. Could you elaborate on what are the uses cases for that module vs workerize-loader
? When to prefer one over another.
Hi @whitecolor - glad you found the inline option.
Worker-plugin is a more standards-oriented approach to bundling Workers. It is lower level than workerize-loader
, in that it doesn't automatically make your worker's methods callable from the main thread. That means it's more similar to the Webpack official worker-loader
in terms of what it provides you. The key feature of worker-plugin
is that the code you write is actually valid browser JavaScript - no webpack-specific import prefixes.
Plugin | What it does |
---|---|
worker-loader |
Bundle workers imported with a prefix or matched by config |
workerize-loader |
Bundle workers imported with a prefix or matched by config, and proxy exported methods calls to the Worker |
worker-plugin |
Bundle Workers created using new Worker("..",{type:"module"}) , compiling them to classic Workers. |
@developit also do you know any drawbacks when using inline
worker creation vs from script url?