Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 30, 2026·3 min de lecture

Workbox — JavaScript Libraries for Progressive Web Apps

A set of production-ready JavaScript libraries from Google Chrome that simplify service worker caching, routing, and offline support for Progressive Web Apps.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Workbox
Commande d'installation directe
npx -y tokrepo@latest install 2236abe1-5c65-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Workbox is a collection of JavaScript libraries maintained by the Google Chrome team that make it easier to build offline-capable Progressive Web Apps. It abstracts complex service worker patterns into simple, composable modules for caching, routing, and background sync.

What Workbox Does

  • Provides pre-built caching strategies (Cache First, Network First, Stale While Revalidate)
  • Generates a service worker with precaching of static assets at build time
  • Offers runtime caching with flexible route matching via URL patterns or regex
  • Handles background sync for deferred network requests when offline
  • Integrates with webpack, Rollup, and other bundlers via plugins

Architecture Overview

Workbox is modular: each concern (routing, caching, precaching, background sync, broadcast updates) lives in its own npm package. The workbox-build module generates a service worker file with a precache manifest at build time. At runtime, workbox-routing intercepts fetch events and delegates to strategy modules like workbox-strategies. This modular design allows tree-shaking to keep the service worker bundle small.

Self-Hosting & Configuration

  • Install workbox-cli or the bundler plugin for your build tool
  • Run workbox wizard to generate a configuration file interactively
  • Use generateSW for a fully generated service worker or injectManifest for custom logic
  • Configure caching strategies per route in workbox-config.js
  • Deploy the generated service worker file alongside your application

Key Features

  • Battle-tested caching strategies with expiration and cache size limits
  • Precaching with revision hashing for reliable static asset updates
  • Background sync queues requests and replays them when connectivity returns
  • Navigation preload support for faster page loads
  • Workbox Window module for communicating between page and service worker

Comparison with Similar Tools

  • sw-precache / sw-toolbox — predecessors now deprecated in favor of Workbox
  • Vite PWA Plugin — uses Workbox under the hood with Vite-specific configuration
  • next-pwa — Next.js wrapper around Workbox for easier integration
  • Service Worker API — raw browser API; Workbox provides higher-level abstractions
  • Remix PWA — Remix-specific offline support; Workbox is framework-agnostic

FAQ

Q: Can I use Workbox with any framework? A: Yes. Workbox is framework-agnostic and works with React, Vue, Angular, vanilla JS, and any build tool.

Q: What is the difference between generateSW and injectManifest? A: generateSW creates the entire service worker for you; injectManifest lets you write custom service worker code and just injects the precache manifest.

Q: Does Workbox handle push notifications? A: Workbox focuses on caching and offline. Push notifications are handled by the Push API directly.

Q: How do I update cached assets? A: Workbox uses revision hashes in the precache manifest and automatically updates stale entries.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires