HTML5 Web Workers for Page or Pages

I looked through a couple of articles that talk about web workers in HTML5, and I couldn't clearly understand the following:

  • Is the life cycle for a web artist limited to just one page or between pages in a domain?
  • Is the life cycle for the web artist saved after the page loads?
  • Do web workers have a better use case than ajax call in setInterval?

Appreciate if someone can help me shed light on the above issues.

+4
source share
1 answer
  • Is the life cycle for a web artist limited to just one page or between pages in a domain?

A dedicated worker is limited to one page, and a shared worker can be linked to many web pages.

  • Is the life cycle for the web artist saved after the page loads?

It can be persistent if defined by onmessage (), and it can also return after execution if I understood correctly. The spec says: let it run until it returns, catch an exception, or be prematurely interrupted by "kill the worker" or "stop the job" ...

  • Do web workers have a better use case than ajax call in setInterval?

It depends. You cannot simply say that it is better or not. Currently, the web worker is mainly used to offload complex JavaScript algorithms to work in the background.

+5
source

Source: https://habr.com/ru/post/1402972/


All Articles