Konubinix' opinionated web of thoughts

Threading the Web With Module Workers

Fleeting

Threading the web with module workers

worker = new Worker(‘worker.js’, { type: ‘module’});

https://web.dev/module-workers/

Copy codeimport { sayHello } from ‘./greet.js’;addEventListener(‘message’, e => { postMessage(sayHello());});

https://web.dev/module-workers/

With module workers, scripts are loaded and executed as standard JavaScript modules, which means they can be preloaded and even pre-parsed using modulepreload:Copy code<!– preloads worker.js and its dependencies: –><link rel=“modulepreload” target="_blank" href=“worker.js”><script> addEventListener(’load’, () => { // our worker code is likely already parsed and ready to execute! const worker = new Worker(‘worker.js’, { type: ‘module’ }); });</script>

https://web.dev/module-workers/