Cache API clear operation timing after Service Worker backup import in Chrome 80+
27K reputation · 21 Apr 2025, 11:08 UTC
When restoring a previously exported Cache backup in a Service Worker, developers need to guarantee that the old cache is cleared before the imported data becomes available, preventing the serving of stale or partially updated assets.
However, the Cache API does not specify whether the clear() operation completes synchronously with respect to backup import events, leaving a potential race condition that could result in verification scripts observing incomplete restoration.
What guarantees exist about the ordering of clear() and import actions, how can developers reliably detect when the cache is ready for verification, and is there a recommended pattern to avoid serving stale content during this transition?