यह पेज अभी हिन्दी में उपलब्ध नहीं है, इसलिए आप इसका अंग्रेज़ी संस्करण पढ़ रहे हैं।

Workbox and Serwist: service worker libraries compared

When to reach for a library, and which one.

सर्विस वर्कर मध्यम 2 मिनट में पढ़ें समीक्षा: 27 नव॰ 2026

Hand-written service workers are fine for small sites. Once you have hundreds of hashed files, several cache types and expiration rules, a library saves time and bugs.

Workbox

Workbox is a set of libraries originally built by Google's Chrome team. It has been the most widely used service worker library for years, and many build tools and frameworks use it underneath. Its main modules:

  • Precaching (workbox-precaching): takes a list of files with revision hashes, made at build time, and keeps them up to date.
  • Routing (workbox-routing): match requests by URL, pattern or function.
  • Strategies (workbox-strategies): CacheFirst, NetworkFirst, StaleWhileRevalidate, NetworkOnly, CacheOnly.
  • Plugins: ExpirationPlugin, CacheableResponsePlugin, BackgroundSyncPlugin, BroadcastUpdatePlugin, RangeRequestsPlugin.
  • Build tools: workbox-cli, workbox-build, workbox-webpack-plugin with generateSW (writes the whole worker) and injectManifest (adds the precache list to your own worker).
  • workbox-window: helps pages register the worker and react to updates.
import { precacheAndRoute } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { NetworkFirst, StaleWhileRevalidate, CacheFirst } from 'workbox-strategies';
import { ExpirationPlugin } from 'workbox-expiration';

precacheAndRoute(self.__WB_MANIFEST);
registerRoute(({ request }) => request.mode === 'navigate', new NetworkFirst({ cacheName: 'pages' }));
registerRoute(({ request }) => request.destination === 'image',
  new CacheFirst({ cacheName: 'images', plugins: [new ExpirationPlugin({ maxEntries: 60, maxAgeSeconds: 30 * 24 * 3600 })] }));
registerRoute(({ request }) => ['style', 'script'].includes(request.destination), new StaleWhileRevalidate({ cacheName: 'assets' }));

Workbox is still maintained, with a slower pace than in its early years (version 7.4 shipped in November 2025).

Serwist

Serwist is a fork of Workbox, started because Workbox development had slowed. Its API is close to Workbox's, but it is modernised: one serwist package instead of many modules, TypeScript first, ES modules, and integrations maintained in the same repository: @serwist/next, @serwist/vite, @serwist/svelte and others.

import { Serwist } from 'serwist';
import { defaultCache } from '@serwist/next/worker';

const serwist = new Serwist({
  precacheEntries: self.__SW_MANIFEST,
  skipWaiting: false,
  clientsClaim: true,
  navigationPreload: true,
  runtimeCaching: defaultCache,
});
serwist.addEventListeners();

Which one?

SituationChoice
Vite, Nuxt, SvelteKit, Astro, React, Vuevite-plugin-pwa (uses Workbox underneath)
Next.jsSerwist (@serwist/next)
Angular@angular/service-worker
webpack, or an existing Workbox setupWorkbox, or migrate to Serwist when convenient
A small static siteHand-written: use our generator

Avoid the older next-pwa package for new projects: it is no longer actively maintained, and Serwist is its natural successor.