@work-bee/core
Caching strategies and events
A tiny ServiceWorker for secure web applications.
Minified + compressed
Test coverage
Privacy first
Import only what you use. Each strategy and middleware is a separate export, keeping your ServiceWorker bundle tiny.
Compose caching strategies with pluggable middleware for fallbacks, logging, offline support, and more.
No third-party code in your ServiceWorker. Fewer supply chain risks, smaller install size, faster installs.
GDPR compliant by design. No tracking, no analytics, no third-party requests from your ServiceWorker.
Cache-first, network-first, stale-while-revalidate, and more. Pick the right strategy for each route.
Queue failed requests, serve fallback pages, and detect connectivity changes out of the box.
Install the core package and create your ServiceWorker in minutes.
npm install @work-bee/coresw.js import { compileConfig, eventInstall, eventActivate, eventFetch, strategyCacheFirst } from "@work-bee/core"
const config = compileConfig({
cachePrefix: "sw-",
routes: [{
methods: ["GET"],
pathPattern: new RegExp("/img/(.+)$"),
cacheName: "img",
strategy: strategyCacheFirst
}]
})
addEventListener("install", (event) => eventInstall(event, config))
addEventListener("activate", (event) => eventActivate(event, config))
addEventListener("fetch", (event) => eventFetch(event, config))if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/sw.js")
}Caching strategies and events
HTTP Cache-Control middleware
Fallback response middleware
User inactivity detection
Logging middleware
Offline request queueing
Save-Data header middleware
Session management middleware
Learn about caching strategies, middleware patterns, and configuration options.