Skip to content

Instantly share code, notes, and snippets.

@yilenpan
Created March 12, 2017 07:21
Show Gist options
  • Save yilenpan/279adda3e997a3d6dd25eaa73095ce02 to your computer and use it in GitHub Desktop.
Save yilenpan/279adda3e997a3d6dd25eaa73095ce02 to your computer and use it in GitHub Desktop.
PracticalServiceWorkers.md

Practical Service Workers

  • Web worker

    • Why do we have web workers?
    • because of the way javascript works
      • (event -> work -> paint)
    • If something in the work part of the loop hangs, the event loop breaks.
    • Web Workers run in a separate thread
      • Doesn't block painting
  • Service Workers

    • Webpage -> service worker -> Internet
      • Event based proxy
    • Async
    • HTTPS Only
    • No access to localStorage
    • Event based
  • Lifecyle and events

    • install
      • this.oninstall = () => {}
    • activate
      • this.onactivate = () => {}
    • fetch
      • this.onfetch = () => {}
    • message
      • this.onmessage = () => {} (2 more)

Building offline applications

  • Fetch
    • Returns a promise
  • Cache
    • cache.put(request, response);
    • CacheStorage.open('key').then(cache => { cache.put(...) });
    • cache.add(url)

Reading Web push notifications at scale

Practical Service Workers

  • Web worker

    • Why do we have web workers?
    • because of the way javascript works
      • (event -> work -> paint)
    • If something in the work part of the loop hangs, the event loop breaks.
    • Web Workers run in a separate thread
      • Doesn't block painting
  • Service Workers

    • Webpage -> service worker -> Internet
      • Event based proxy
    • Async
    • HTTPS Only
    • No access to localStorage
    • Event based
  • Lifecyle and events

    • install
      • this.oninstall = () => {}
    • activate
      • this.onactivate = () => {}
    • fetch
      • this.onfetch = () => {}
    • message
      • this.onmessage = () => {} (2 more)

Building offline applications

  • Fetch
    • Returns a promise
  • Cache
    • cache.put(request, response);
    • CacheStorage.open('key').then(cache => { cache.put(...) });
    • cache.add(url)

Reading Web push notifications at scale

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