Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsMay 30, 2026·3 min de lectura

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.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Workbox
Comando de instalación directa
npx -y tokrepo@latest install 2236abe1-5c65-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con 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

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados