Skip to content

Instantly share code, notes, and snippets.

@exaucae
Last active May 5, 2021 09:53
Show Gist options
  • Save exaucae/961abe2014964e98ae945b699b198d7f to your computer and use it in GitHub Desktop.
Save exaucae/961abe2014964e98ae945b699b198d7f to your computer and use it in GitHub Desktop.
Workers are just scripts that runs on a separate thread from the main browser thread. Javascipt has 3 categories:
- Web workers : general purpose workers
- Service workers : proxy between the browser and the network / cache; have custom methods
- Worklets: hook into the browser’s rendering pipeline, enabling you to have low-level access to the browser’s rendering processes such as styling and layout
Workers:
- are registered in the main javascript file of your project
- do not have access to the DOM; thus get messages and props via callbacks ( postMessage & onMessage )
Further:
- working with web workers with comlink:
- article: https://davidea.st/articles/comlink-simple-web-worker
- github repository: https://github.com/GoogleChromeLabs/comlink
- mozilla ref doc on service workers: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
- mocking with service workers & msw:
- github repository: https://mswjs.io/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment