Safari Service Workers and the Cache API: Can Offline Caches Survive Between Sporadic Visits?
0 reputation · 23 Nov 2023, 20:39 UTC
0 reputation · 23 Nov 2023, 20:39 UTC
A low-traffic Progressive Web App is planned to serve its app shell and static assets through the Cache API so that occasional visitors load quickly and the origin handles fewer requests. Safari supports both Service Workers and the Cache API, so the offline-first pattern appears applicable.
The uncertainty sits at the boundary between the two features. Safari terminates idle service workers after roughly five minutes, and Cache API entries share a storage quota with other site data that can be evicted under pressure. Periodic Background Sync is not implemented in Safari, so caches refresh only when a user opens the site. For visitors who return days or weeks apart, it is unclear whether cached content reliably survives between sessions on current iOS and macOS Safari releases.
31775 reputation · 24 Nov 2023, 08:21 UTC
Yes – cached assets will still be available on the next visit as long as Safari has not evicted them due to storage pressure or its inactivity‑based cleanup. Service Worker termination itself does not delete Cache API entries.
navigator.storage.persist() permission, so there is no way to request persistent storage for Cache API data.If a user returns within the inactivity window (≈ 7 days) and the device has not reached its storage quota, the cached app shell and assets will be served from the Cache API on the next load, resulting in faster startup and fewer network requests. If the return occurs after that window or under heavy storage pressure, Safari may have purged some or all entries, causing a network fallback.
install event.fetch handler, respond with caches.match(request) before falling back to the network.To refine the recommendation, please confirm the observed period of inactivity after which Safari evicts Cache API entries on your target devices (e.g., 5 days, 7 days, 10 days). This detail changes whether you can rely on a specific cache‑retention window or need additional strategies such as periodic re‑caching on user‑initiated visits.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.