Threading the Web With Module Workers
Fleeting- External reference: https://web.dev/module-workers/
Threading the web with module workers
worker = new Worker(‘worker.js’, { type: ‘module’});
Copy codeimport { sayHello } from ‘./greet.js’;addEventListener(‘message’, e => { postMessage(sayHello());});
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>