Is IndexedDB on Safari guaranteed to be persistent?
Asked Answered
C

3

7

Similar to this question, is IndexedDB guaranteed to be persistent ? ie. Safari will not reclaim disk space if the device is low on memory.

Corabelle answered 11/6, 2018 at 10:16 Comment(1)
In my experience so far using IndexedDB for a PWA, desktop Safari is stable, but iOS Safari is not. IndexedDB data seems to get periodically wiped for reasons we haven't been able to nail down – sometimes seems to just be the session expired? It's extremely alarming, so defs follow @anand's advance and build with fallback options.Isidoro
O
8

Safari have "No Eviction policy", meaning it will not automatically clean the IndexDB on low disk pressure, without user doing it manually.

IndexDB is one of the fast evolving feature and you can expect to have a different eviction policy any time with no announcement. You should always build with fall back options.

Chrome has explicit persistent storage option which will guarantee no eviction, on user approval for persistent storage and we can expect Safari to do the same sometime, based on their track record of following Chrome in implementing PWA features(though its taking years with super bad documentation).

Overdress answered 13/6, 2018 at 0:31 Comment(2)
It seems IndexedDb falls in the "best effort" storage strategy for which iOS Safari (11.3+) hints that your data might be wiped after a few weeks (2-3) of inactivity (app is unused).Emmery
Update from March 24, 2020, from your Safari article link: "Starting in iOS and iPadOS 13.4 and Safari 13.1 on macOS, there is a seven-day cap on all script writable storage, including IndexedDB, service worker registration, and the Cache API. This means Safari will evict all content from the cache after seven days of Safari use if the user does not interact with the site. This eviction policy does not apply to installed PWAs that have been added to the home screen."Edytheee
D
6

According to this blog post from the WebKit team, IndexedDB is not guaranteed to be persistentfrom iOS and iPadOS 13.4 and Safari 13.1 on macOS. Safari will delete it after seven days of Safari usage without interaction with the site:

Now ITP has aligned the remaining script-writable storage forms with the existing client-side cookie restriction, deleting all of a website’s script-writable storage after seven days of Safari use without user interaction on the site. These are the script-writable storage forms affected (excluding some legacy website data types):

  • Indexed DB
  • LocalStorage
  • Media keys
  • SessionStorage
  • Service Worker registrations and cache

However, IndexedDB is pretty much guaranteed to be persistent if your Web app is installed in your Home Screen, as the Web app will have its own usage context, and due to its very nature, it'd be impossible to use it for seven days without accessing the site where it came from:

[...] Web applications added to the home screen are not part of Safari and thus have their own counter of days of use. Their days of use will match actual use of the web application which resets the timer. We do not expect the first-party in such a web application to have its website data deleted.

Regardless of the above, I would personally not trust IndexedDB for any kind of long-term data storage. I've found it quite ropey, and not long ago broke altogether in Safari 14.1.1.

Deemphasize answered 26/10, 2021 at 11:35 Comment(0)
G
0

I have no definitive answer, but after using IndexedDB for over 2 years in a big browser/desktop (electron based) application I would attribute multiple datalosses to IndexedDB or at least IndexedDB in chrome. So my answer would be no. Don't rely on it.

Gasperoni answered 17/9, 2020 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.