DEV Community

Discussion on: Explain how service workers work like I'm five

Collapse
 
timothymehlhorn profile image
Tim Mehlhorn

Imagine that your browser is it's own planet in space and wants to talk other planets in the galaxy. The way 'planets' talk to each other is via a giant space pipe (HTTP protocol). Sometimes that giant pipe is not around so you can't talk with other planets (offline).

This where Service Workers can come in. Service Workers are like alien spaceships that can sit between the space pipe and your planet. When the service worker is around everything goes through it first, and it can remember what came through the pipe.

For example, there is a service worker around but no space pipe(offline) and you ask for the cat gif that you saw yesterday, the service worker can give you that cat gif without the space pipe(network) because it remembers it (service worker cache).

Check the source for an even better explanation.

Service Worker as alien spaceships

Source: Service Worker, what are you ? by @kosamari