Office worker versus general worker

What is the difference between Service Worker and Shared Worker?

When should I use Service Worker instead of general worker and vice versa?

+24
javascript html5 web-worker service-worker
Mar 05 '15 at 16:02
source share
2 answers

The employee has additional functionality beyond what is available in general employees, and after registration they are stored outside the life of this web page.

Service employees can respond to message events, such as general employees, but also have access to additional events. Fetch event processing allows service workers to intercept any network traffic (coming from a controlled page) and perform certain actions, including response from the Request / Response cache. There are also plans to show the push event to staff, allowing web applications to receive push messages in the background.

Another important difference relates to perseverance. Once a service worker is registered for a specific origin and volume, he remains registered for an indefinite period. (The service employee is automatically updated if the base script changes, and it can be deleted manually or programmatically deleted, but this is an exception.) Since the service employee is persistent and has a life independent of the pages active in the web browser, it opens the door for such things as using them to power the aforementioned push message - a service worker can β€œwake up” and handle the push event while the browser is running, regardless of which pages are active. Future features of the web platform are likely to take advantage of this persistence.

There are other technical differences, but from a higher level point of view, this is what stands out.

+14
Mar 06 '15 at 22:49
source share
β€” -

A SharedWorker context is a stateful session and is designed to multiplex web pages into one application through asynchronous messaging (client / server paradigm). Its life cycle is based on a domain, not on a single page, like DedicatedWorker (a two-level paradigm).

The ServiceWorker context is designed to be inactive. This is actually not a permanent session - it is an inversion of management (IoC) or an event-based service paradigm. It caters for stateless events, not stateful pages.

One goal is to provide concurrent secure asynchronous endpoints for long queries (LRQ) for databases and other storage services (such as the cloud). Exactly what the thread pool does in other languages.

For example, if your web application runs many concurrent secure LRQs for various cloud services to populate itself, ServiceWorkers is what you want. You can execute dozens of secure LRQs in seconds without blocking the user's work. SharedWorkers and DedicatedWorkers have a hard time managing multiple concurrent secure LRQs. In addition, some browsers do not support SharedWorkers .

Perhaps they should have called ServiceWorkers : CloudWorkers for clarity, but not all services are clouds.

We hope this explanation should make you think about how different types of workers were designed to work together. Each of them has its own specialization, but the overall goal is to reduce DOM latency and improve the user interface in web applications.

Download some WebSockets for push notifications and WebGL for graphics, and you can create some hot smoking web applications that work like multi-user console games.

+8
Nov 27 '16 at 1:58
source share



All Articles