A service worker is a Javascript file that operates separately from the leading browser network in the background and intercepts all requests regarding the network, caches data, and gives a building block for many APIs like push notifications, caching, and background refresh. In simple terms, the service worker is the element responsible for giving functionality to an app even when it is closed. It enables the app to be offline-first.