Inferensys

Glossary

Service Workers

A script that runs in the browser's background, separate from a web page, acting as a programmable network proxy to enable features like offline caching, background sync, and push notifications.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
PROGRAMMABLE NETWORK PROXY

What is a Service Worker?

A service worker is a script that the browser runs in the background, separate from a web page, acting as a programmable intercepting proxy to enable features like offline caching, background synchronization, and push notifications.

A service worker is a JavaScript file that operates as a client-side proxy between a web application and the network. It intercepts all outgoing HTTP requests from a page, allowing developers to programmatically control the response. This enables a web app to serve cached assets when the network is unavailable, providing a reliable offline experience. Because it runs on a separate thread, it never blocks the main UI thread.

The lifecycle of a service worker involves distinct phases: install, activate, and fetch. During installation, critical resources are pre-cached using the Cache API. Once activated, the worker can manage network requests, implement custom caching strategies like stale-while-revalidate, and handle background sync events. Critically, service workers require HTTPS for security, preventing man-in-the-middle attacks on the programmable proxy.

PROGRAMMABLE NETWORK PROXY

Core Capabilities of Service Workers

Service workers act as a client-side proxy, intercepting all network requests from a page to enable offline experiences, background synchronization, and push notifications independent of the web page lifecycle.

01

Offline Interception & Caching

The service worker's fetch event acts as a programmable proxy, intercepting every HTTP request. This enables Cache-First, Network-First, or Stale-While-Revalidate strategies. By serving pre-cached assets from the Cache API, the application remains fully functional without a network connection, eliminating the 'No Internet' dinosaur.

< 1 sec
Cache-First Load Time
02

Background Sync

Using the SyncManager interface, service workers defer network operations until stable connectivity returns. If a user submits a form while offline, the request is stored in IndexedDB and a sync event is registered. The browser fires the event when back online, ensuring reliable atomic data uploads without user intervention.

03

Push Notifications

Service workers decouple notifications from the browser tab lifecycle via the Push API and Notifications API. The worker listens for a push event from an application server, even when the page is closed, and displays a system notification. This relies on the Web Push Protocol and a subscription object generated by the browser's push service.

04

Lifecycle & Registration

A service worker follows a strict lifecycle: Registration -> Installation (ideal for pre-caching critical shell assets) -> Activation (ideal for clearing old caches). It terminates when idle and restarts on event. Registration via navigator.serviceWorker.register() scopes the worker to a specific directory path, preventing cross-origin interference.

05

HTTPS Requirement

Service workers require a secure context (HTTPS) to prevent man-in-the-middle attacks. Because the worker intercepts and modifies all network requests, arbitrary script injection would be catastrophic. The localhost exception exists purely for development convenience, but production deployment demands valid TLS certificates.

06

IndexedDB Storage

Service workers cannot access the DOM or localStorage (synchronous API). Instead, they use the asynchronous IndexedDB API for persistent, structured data storage. This is critical for queuing failed requests, storing API responses for offline navigation, and maintaining user session data outside the main thread.

SERVICE WORKER ESSENTIALS

Frequently Asked Questions

Clear, technical answers to the most common questions about the programmable network proxy that powers offline experiences, background sync, and push notifications.

A service worker is a JavaScript file that runs in the browser's background, completely separate from a web page, acting as a programmable network proxy between the browser and the network. It intercepts all network requests originating from pages under its scope, allowing developers to control how those requests are handled—whether served from the network, a local cache, or a custom response. Service workers are event-driven, terminating when idle and restarting when needed, making them fundamentally different from traditional JavaScript execution contexts. They enable features previously exclusive to native applications: offline functionality, background data synchronization, and push notifications. Because they sit between the page and the network, service workers require HTTPS to prevent man-in-the-middle attacks, with localhost being the only exception for development purposes.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.