sw-toolbox vs workbox-background-sync vs workbox-cacheable-response vs workbox-core vs workbox-routing
Service Worker Tooling: Legacy sw-toolbox vs Modern Workbox Modules
sw-toolboxworkbox-background-syncworkbox-cacheable-responseworkbox-coreworkbox-routingSimilar Packages:

Service Worker Tooling: Legacy sw-toolbox vs Modern Workbox Modules

sw-toolbox is a legacy library for managing service workers, now superseded by the workbox ecosystem. The workbox-* packages (workbox-core, workbox-routing, workbox-cacheable-response, workbox-background-sync) represent the modular architecture of Workbox, allowing developers to import only the specific functionality needed for caching strategies, request routing, and offline reliability. While sw-toolbox provided a simple script-tag approach, Workbox offers a build-step integrated, promise-based API that aligns with modern JavaScript standards.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
sw-toolbox79,5223,583-569 years agoApache-2.0
workbox-background-sync012,984302 kB1014 months agoMIT
workbox-cacheable-response012,98488.4 kB1014 months agoMIT
workbox-core012,984304 kB1014 months agoMIT
workbox-routing012,984271 kB1014 months agoMIT

Service Worker Tooling: Legacy sw-toolbox vs Modern Workbox Modules

Building reliable offline-first web apps requires precise control over network requests. For years, sw-toolbox was the go-to solution for simplifying service worker logic. Today, the workbox suite has replaced it with a modular, build-ready approach. Let's compare how these tools handle routing, caching, and reliability.

🏗️ Architecture: Monolithic Script vs Modular Imports

sw-toolbox was designed to be dropped into a project via a script tag or simple import. It bundled routing and caching strategies into one global namespace. This made it easy to start but hard to optimize for bundle size.

// sw-toolbox: Global namespace approach
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.2/workbox-sw.js');

const router = new workbox.routing.Router();
router.registerRoute(
  /.*\.js/,
  workbox.strategies.cacheFirst()
);

workbox-* packages are modular npm libraries. You import only what you need. This tree-shaking friendly approach reduces bundle size and integrates with modern build tools like Webpack or Vite.

// workbox-routing: Modular import
import { registerRoute } from 'workbox-routing';
import { CacheFirst } from 'workbox-strategies';

registerRoute(
  /.*\.js/,
  new CacheFirst()
);

🛣️ Request Routing: Patterns and Handlers

sw-toolbox used a router instance to map URL patterns to handlers. It relied on regular expressions or path strings defined at the top of the service worker file.

// sw-toolbox: Router instance
const router = new workbox.routing.Router();
router.registerRoute(
  '/api/*',
  workbox.strategies.networkFirst()
);

workbox-routing simplifies this with a standalone registerRoute function. It supports the same pattern matching but integrates better with TypeScript and modern JavaScript syntax.

// workbox-routing: Standalone function
import { registerRoute } from 'workbox-routing';
import { NetworkFirst } from 'workbox-strategies';

registerRoute(
  ({ url }) => url.pathname.startsWith('/api/'),
  new NetworkFirst()
);

💾 Caching Logic: Status Codes and Headers

sw-toolbox had limited built-in filtering for cacheable responses. Developers often had to write custom handlers to check status codes before caching, leading to verbose code.

// sw-toolbox: Manual status check
router.registerRoute(
  /.*\.png/,
  (request, response) => {
    if (response.status === 200) {
      return caches.open('images').then(cache => cache.put(request, response));
    }
  }
);

workbox-cacheable-response provides a plugin to handle this automatically. You attach it to a strategy, and it ensures only valid responses (e.g., status 200) are stored.

// workbox-cacheable-response: Plugin configuration
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
import { StaleWhileRevalidate } from 'workbox-strategies';
import { registerRoute } from 'workbox-routing';

registerRoute(
  /.*\.png/,
  new StaleWhileRevalidate({
    plugins: [
      new CacheableResponsePlugin({
        statuses: [0, 200]
      })
    ]
  })
);

🔄 Offline Reliability: Queuing Failed Requests

sw-toolbox did not have a built-in background sync feature. Developers had to implement IndexedDB storage and retry logic manually, which was error-prone and complex.

// sw-toolbox: No built-in sync
// Developers had to write custom IndexedDB logic to store failed requests
// and replay them on 'online' events.

workbox-background-sync offers a dedicated plugin for this exact scenario. It intercepts failed requests, stores them in IndexedDB, and automatically retries them when the network returns.

// workbox-background-sync: Plugin for retry logic
import { BackgroundSyncPlugin } from 'workbox-background-sync';
import { NetworkOnly } from 'workbox-strategies';
import { registerRoute } from 'workbox-routing';

const bgSyncPlugin = new BackgroundSyncPlugin('myQueueName', {
  maxRetentionTime: 24 * 60 // Retry for max of 24 hours
});

registerRoute(
  '/api/save',
  new NetworkOnly({
    plugins: [bgSyncPlugin]
  }),
  'POST'
);

⚙️ Core Utilities: Logging and Cache Management

sw-toolbox included core utilities implicitly. There was no separate package for low-level functions like cache naming or versioning, which sometimes led to conflicts in larger apps.

// sw-toolbox: Implicit core
// Cache names were often global strings defined manually
const cacheName = 'my-app-v1';

workbox-core exposes these utilities explicitly. It helps manage cache versions, log debug information, and assert preconditions without pulling in routing or strategies.

// workbox-core: Explicit utilities
import { cacheNames, setCacheNameDetails } from 'workbox-core';

setCacheNameDetails({
  prefix: 'my-app',
  suffix: 'v1'
});

console.log(cacheNames.runtime);

🚨 Deprecation Status: The Critical Difference

sw-toolbox is officially deprecated. The Google team stopped updates years ago. Using it introduces security risks and compatibility issues with newer browser service worker standards.

// sw-toolbox: DO NOT USE
// importScripts('.../sw-toolbox.js'); // Deprecated

workbox-* packages are actively maintained. They receive regular updates for new browser features, security patches, and build tool integrations.

// workbox: Current Standard
// npm install workbox-routing workbox-strategies // Active

🌐 Real-World Scenarios

Scenario 1: Caching Static Assets

You need to cache CSS and JS files aggressively.

  • Best choice: workbox-routing + workbox-strategies
  • Why? Modular import keeps bundle small; CacheFirst strategy is standard.
registerRoute(
  /.*\.(js|css)/,
  new CacheFirst()
);

Scenario 2: API Fallbacks

Your API should try network first, but fall back to cache if offline.

  • Best choice: workbox-routing + workbox-cacheable-response
  • Why? Ensures you don't cache error pages like 500 or 404.
registerRoute(
  '/api/*',
  new NetworkFirst({
    plugins: [new CacheableResponsePlugin({ statuses: [200] })]
  })
);

Scenario 3: Critical User Data

Users submit forms that must not be lost if they lose connection.

  • Best choice: workbox-background-sync
  • Why? Automatically handles the queue and retry logic without custom IndexedDB code.
new NetworkOnly({
  plugins: [new BackgroundSyncPlugin('formSubmissions')]
});

📊 Summary Table

Featuresw-toolboxworkbox-* Modules
Status❌ Deprecated✅ Actively Maintained
Import StyleGlobal Script / importScriptsES6 Modules / import
Routingrouter.registerRouteregisterRoute function
Caching FiltersManual ChecksCacheableResponsePlugin
Offline QueueManual ImplementationBackgroundSyncPlugin
Build IntegrationPoor (Runtime)Excellent (Build Step)

💡 Final Recommendation

sw-toolbox belongs in legacy maintenance mode only. If you see it in an existing codebase, plan a migration. It lacks the modularity and safety features required for modern web apps.

workbox-* packages are the industry standard. Start with workbox-routing and workbox-strategies for basic caching. Add workbox-background-sync for critical data and workbox-cacheable-response to keep your cache clean. Use workbox-core only if you need deep customization.

Final Thought: The shift from sw-toolbox to Workbox reflects the broader move in JavaScript towards modular, build-optimized tooling. Embrace the modules — they make service workers less magic and more engineering.

How to Choose: sw-toolbox vs workbox-background-sync vs workbox-cacheable-response vs workbox-core vs workbox-routing

  • sw-toolbox:

    Do NOT choose sw-toolbox for new projects. It is deprecated and no longer maintained by the Google Chrome team. Existing projects using it should plan a migration to Workbox to ensure security updates and compatibility with modern browser service worker APIs.

  • workbox-background-sync:

    Choose workbox-background-sync if your application requires reliable data submission when users are offline. It queues failed requests and replays them when connectivity returns, making it the standard choice for forms, analytics, or critical user actions that cannot be lost.

  • workbox-cacheable-response:

    Choose workbox-cacheable-response when you need to filter which HTTP responses get stored in the cache based on status codes or headers. This is critical for avoiding caching error pages (like 404s) or ensuring only successful API responses are stored for offline use.

  • workbox-core:

    Choose workbox-core if you are building custom service worker logic that requires low-level utilities like logging, cache naming, or precise timestamping without the overhead of higher-level strategies. It is rarely used directly by application developers unless creating custom plugins.

  • workbox-routing:

    Choose workbox-routing when you need to define specific URL patterns that trigger different caching behaviors. It is essential for separating static assets from API calls, allowing you to apply distinct strategies to different parts of your application traffic.

README for sw-toolbox

Service Worker Toolbox

Build Status Dependency Status devDependencies Status

A collection of tools for service workers

Service Worker Toolbox provides some simple helpers for use in creating your own service workers. Specifically, it provides common caching strategies for dynamic content, such as API calls, third-party resources, and large or infrequently used local resources that you don't want precached.

Service Worker Toolbox provides an expressive approach to using those strategies for runtime requests. If you're not sure what service workers are or what they are for, start with the explainer doc.

What if I need precaching as well?

Then you should go check out sw-precache before doing anything else. In addition to precaching static resources, sw-precache supports optional runtime caching through a simple, declarative configuration that incorporates Service Worker Toolbox under the hood.

Install

Service Worker Toolbox is available through Bower, npm or direct from GitHub:

bower install --save sw-toolbox

npm install --save sw-toolbox

git clone https://github.com/GoogleChrome/sw-toolbox.git

Register your service worker

From your registering page, register your service worker in the normal way. For example:

navigator.serviceWorker.register('my-service-worker.js');

As implemented in Chrome 40 or later, a service worker must exist at the root of the scope that you intend it to control, or higher. So if you want all of the pages under /myapp/ to be controlled by the worker, the worker script itself must be served from either / or /myapp/. The default scope is the containing path of the service worker script.

For even lower friction, you can instead include the Service Worker Toolbox companion script in your HTML as shown below. Be aware that this is not customizable. If you need to do anything fancier than register with a default scope, you'll need to use the standard registration.

<script src="/path/to/sw-toolbox/companion.js" data-service-worker="my-service-worker.js"></script>

Add Service Worker Toolbox to your service worker script

In your service worker you just need to use importScripts to load Service Worker Toolbox:

importScripts('bower_components/sw-toolbox/sw-toolbox.js');  // Update path to match your own setup.

Use the toolbox

To understand how to use the toolbox read the Usage and API documentation.

Support

If you’ve found an error in this library, please file an issue at https://github.com/GoogleChrome/sw-toolbox/issues.

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through this GitHub repo.

License

Copyright 2015-2016 Google, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.