What are Service Workers?

Usually, the JavaScript code that we use to build web applications is single-threaded, attached to individual pages, and can be used for actions, such as:

  • Manipulating the DOM of HTML pages.
  • Showing alerts.
  • Prompting the user for input.

Service workers

A service worker is a web worker that runs as a background process irrespective of whether the app is running. It runs on a single thread other than the main UI thread of a web page.

A service worker is attached to any particular scope and manages all its pages. The service worker can’t manipulate the DOM because it’s not attached to a page.

Get hands-on with 1200+ tech skills courses.