Skip to main content
InterviewHubPRO
Section Overview
Q27

Question 27 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

54%
HTML5 & Web APIs (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Service Workers: Lifecycle (`install`, `activate`, `fetch`) and Offline PWAs.

senior LevelCode ExampleLifecycleSystem DesignHTTP & REST APIs

In Simple Words: A Service Worker is an event-driven programmable network proxy sitting between the browser, the web application, and the network:

css
[ Web Application ] <==== HTTP Request ====> [ Service Worker Proxy ] <====> [ Network ]
                                                      |
                                                      v
                                              [ Cache Storage ]

The 3 Lifecycle Phases:

  1. install: Service worker downloads and precaches static assets (cache.addAll(['/', '/style.css', '/bundle.js'])).
  2. activate: Cleans up old, stale cache versions from previous service workers.
  3. fetch: Intercepts every network request made by the web application. Can return cached data instantly (Cache-First), fall back to the network (Network-First), or use Stale-While-Revalidate.