Persistence lifetime
IndexedDB data belong to a type of temporary. So these data can be wiped out at any time.
These data size/lifetime are managed by very new Quota Management API.
In the future, IndexedDB could possibly used persistance type (not likely and not good idea too).
Persistent Storage has been available in Chrome since v52 and Firefox since v55. Support in other browsers can't be relied on though. You must test if persistent storage is available and react accordingly.
if (navigator.storage && navigator.storage.persist) {
navigator.storage.persist().then(persistent => {
if (persistent) {
console.log("Storage will not be cleared except by explicit user action");
} else {
console.warn("Storage may be cleared by the UA under storage pressure.");
}
});
}
Chrome requires permission to use this feature. It will automatically be granted when calling navigator.storage.persist()
if any of the following are true:
- The site is bookmarked (and the user has 5 or less bookmarks)
- The site has high site engagement
- The site has been added to home screen on mobile device
- The site has push notifications enabled
This list comes from an article outlining Chrome's implementation which is updated periodically with new information about this subject.
It's like localStorage
, so it's cross-session, meaning restarting browser or system won't affect what is stored in it. However, user can clear it like clearing cookie. So it's just like persistent cookie, you don't trust it from the server-side, and you always need to check its integrity.