A simple service worker library for request caching
swimple provides automatic caching with smart invalidation for your service worker.
Request caching with automatic invalidation by default - minimal setup required
Automatically invalidate cache on mutations (POST/PATCH/PUT/DELETE)
Support for cache-first, network-first, and stale-while-revalidate
Single-purpose library with no dependencies
Make API requests and watch them get cached automatically. Try mutations to see cache invalidation in action.
These are the entries in the browser's cache that swimple has handled.
// sw.js
import { createHandleRequest } from "https://cdn.jsdelivr.net/npm/swimple@1.0.0/index.js";
const handleRequest = createHandleRequest({
cacheName: "sw-cache-v1",
scope: ["/api/"]
});
self.addEventListener("fetch", (event) => {
const response = handleRequest(event);
if (response) {
event.respondWith(response);
}
});