import * as Comlink from ‘comlink’
// worker.js
const request = () => {
const url = new URL('AD_SERVER_ENDPOINT')
url.searchParams = { /*...*/ }
return fetch(
url.toString(),
{ headers: { /*...*/ } }
).then((res) => res.json())
}
Comlink.expose(request)
// main.js
const request = Comlink.wrap(
new Worker(paths.controllerWorker)
)
// ...
if (useWorker) {
request(sectionId).then(renderAd)
}
Off The Main Thread
ࠂεΫϦϓτͷ࠷దԽ