JSFiddle - React, Tailwind, and code Playground
JavaScript
// our worker creates a url that when loaded will log a message!
const src = `
onmessage = (evt) => {
const logSrc = 'console.log('+JSON.stringify(evt.data)+')'
const logURL = URL.createObjectURL(
new Blob([logSrc], {type:'text/javascript'}));
postMessage(logURL);
}
`
const workURL = URL.createObjectURL(
new Blob([src], {type:'text/javascript'}));
const worker = new Worker(workURL);
worker.onmessage = (evt) => {
new Worker(evt.data);
}
worker.postMessage('hiya!');