home / skills / harborgrid-justin / lexiflow-premium / service-worker-caching-strategies
/frontend/.github-skills/service-worker-caching-strategies
This skill helps you implement offline caching and asset management for React apps using service workers, improving reliability and performance.
npx playbooks add skill harborgrid-justin/lexiflow-premium --skill service-worker-caching-strategiesReview the files below or copy the command above to add this skill to your agents.
---
name: service-worker-caching-strategies
description: Implement robust offline caching and asset management for React apps via Service Workers.
---
# Service Worker Caching Strategies
## Summary
Implement robust offline caching and asset management for React apps via Service Workers.
## Key Capabilities
- Cache app shell and assets.
- Implement runtime caching.
- Handle service worker updates.
## PhD-Level Challenges
- Prevent cache poisoning.
- Debug scoping issues.
- Manage quota interaction.
## Acceptance Criteria
- Demonstrate offline launch.
- Show update prompt.
- Provide a cache strategy.
This skill implements robust offline caching and asset management for React apps using Service Workers. It provides app-shell caching, runtime caching rules, and an update flow to notify users when a new version is available. The goal is reliable offline launches, controlled cache updates, and reduced network load.
The skill installs a Service Worker that precaches the app shell and static assets at install time, then applies runtime caching strategies (cache-first, network-first, or stale-while-revalidate) for API responses and media. It includes logic to compare cache versions, evict stale entries, and surface an update prompt when a new Service Worker is waiting to activate. It also includes safeguards to limit cache size and prevent common pitfalls like cache poisoning and scope misconfiguration.
How do I prevent cache poisoning?
Validate responses before caching (status 200, correct content-type), scope caches narrowly, and avoid caching user-submitted data without strict checks.
How can I prompt users about updates?
Listen for the Service Worker 'waiting' state in the client, show a banner or toast, and call skipWaiting/clients.claim on user confirmation to activate the new worker.