Level Up your UI Game

Service Workies Ch3 — Control

Service Workies chapter 3 is released and ready to play!

Up to this point in the game you've learned about the Service Worker lifecycle and how to react to it. With that foundation in place now in chapter three you'll learn one of the most powerful things a Service Worker can do — intercept http requests.

Intercept

A Service Worker, once installed and activated, sits in between your web page and the network. It can see every single request from the Page its installed on using its fetch event listener. With that powerful hook you can decide what you want to do with each request. Using respondWith you can send back anything you want, including something from a cache.

intercepting requests

Control

Service Workers can be stopped at any time. Including when you close a browser tab — which is what closing the Portal in game is simulating. The browser tab closes but its Service Workers sticks around, and is even still active — ready to intercept the very first request for the page the next time you revisit that site. This behavior is what allows a Service Worker to take full control of a site's entire network activity.

I wanted to model this in game, giving you an even clearer mental model for when you build your own Service Workers. So now Kolohe turns silhouette when you close the Portal, and grapples into position before the Page code request if he's currently in control.

stopped service worker

Good Luck Have Fun

The release of this chapter took a minute to create, and had to wait for the big polish release we shipped. But I think will be well worth the wait.

Hope you have a blast while you learn. Happy hunting!

Play Now
Service Worker Game

PWAs are the future of web apps. At their very heart is the powerful but devious Service Worker. Learn to control it inside and out, and make your web app compete with the very best of native.Master Service Workers