Web Workers with Vue
Comlink for typed web worker API, offloading heavy computation, reactive progress tracking.
Why Web Workers
JavaScript runs on a single main thread shared with rendering. Heavy computation freezes the UI. A Web Worker runs code on a separate thread, keeping your Vue app responsive.
Creating a Worker
Instantiate a worker from a module file. Vite supports the { type: "module" } option and bundles the worker correctly.
const worker = new Worker(
new URL("./worker.js", import.meta.url),
{ type: "module" }
);