Skip to content

Instantly share code, notes, and snippets.

@originalhat
Last active December 8, 2017 17:47
Show Gist options
  • Save originalhat/6a0785d5bc5ae063877b to your computer and use it in GitHub Desktop.
Save originalhat/6a0785d5bc5ae063877b to your computer and use it in GitHub Desktop.
Service Workers

Service Workers

A service worker is a script that is run by your browser in the background, separate from a web page, opening the door to features which don't need a web page or user interaction. Rich offline experiences, periodic background syncs, push notifications— functionality that would normally require a native application—are coming to the web.

  • SW are are just JS workers, so they can't access the DOM directly
  • a SW can communicate w/ the pages it controls by responding to message sent via the postMessage interface
  • SW is a programmable network proxy, allowing you to conrol how network requests from your page are handled
  • it runs only when needed, and terminiates when unneeded (cannot rely on global state)
  • service workers make extense use of promises

SW Lifecycle

  • to install a SW, you need to register it in your page's JS

sw-lifecycle

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment