

These come in the form of Google Chrome extensions. While there are some things you can do to mitigate this, like finding a place to work that's not where you play, being strict with cut off times to stop working, and making sure you take regular breaks, there are also some other hacks that we think can help your work-from-home process. On the other hand, working from home turns your cozy sanctuary into an extension of your workplace, and it can be hard to switch off the way you normally would when you leave a physical place. Your commute is however far it is from your bed to your laptop, you don't have to deal face-to-face with annoying colleagues, you can make your own homemade, healthy snacks, and yes, you can work in your pajamas. On one hand working from home is truly awesome. Registration is the initial step of the service worker lifecycle: Let's begin with what happens when a brand new service worker is deployed for a website with no active service worker. In order for a service worker to control a page, it must first be brought into existence, so to speak. Specifically, these are instances of a WindowClient. A client is any open page whose URL falls within the scope of that service worker. When it's said that a service worker is controlling a page, it's really controlling a client. It's a lot simpler for everyone that way. Unless there's a very good reason to limit service worker scope to a subset of an origin, load a service worker from the root directory of the web server so that its scope is as broad as possible, and don't worry about the Service-Worker-Allowed header. The above is how scoping works by default, but the maximum allowed scope can be overridden by setting the Service-Worker-Allowed response header, as well as passing a scope option to the register method. Scope limits which pages are controlled by a service worker, not which requests it can intercept. Note: Regardless of scope, a service worker controlling a page can still intercept any network requests, including those for cross-origin assets.

In this example, that means the service worker loaded from /subdir/sw.js can only control pages located in /subdir/ or its subtree. Scope limits what pages the service worker controls. That's because this page is not within the registered service worker's scope. Even though a service worker was registered on this origin, there's still a message saying there is no current service worker. Note: having to reload the page has nothing to do with scope, but rather the service worker lifecycle, which will be explained later on. A form containing the service worker's scope, current state, and its URL will be visible. Because the service worker has been registered and is now active, it's controlling the page. However, that page registers a service worker from. A message will appear that says no service worker is controlling the page. To see the concept of scope in action, check out this example: If a service worker runs on a page located at /subdir/index.html, and is located at /subdir/sw.js, the service worker's scope is /subdir/. # ScopeĪ service worker's scope is determined by its location on a web server. The service worker is present and able to do work for the page within a given scope. A page described as being controlled by a service worker is a page that allows a service worker to intercept network requests on its behalf. The idea of control is crucial to understanding how service workers operate. # Defining termsīefore getting into the service worker lifecycle, it's worth defining some terms around how that lifecycle operates. It helps to remember that-like any other browser API-service worker behaviors are well-defined, specified, and make offline applications possible, while also facilitating updates without disrupting the user experience.īefore diving into Workbox, it's important to understand the service worker lifecycle so that what Workbox does makes sense. Their inner workings will seem opaque, even arbitrary. It's hard to know what service workers are doing without understanding their lifecycle.
