如何使网络应用程序的数据“持久"而不是“尽力而为"?我想避免在没有足够空间的情况下清除数据 [英] How do I make the data of a web app "persistent" as opposed to "best-effort"? I want to avoid the data being cleared when there is not enough space
问题描述
根据 https://developer.mozilla.org /en-US/docs/Web/API/StorageManager/persist ,您可以将框标记为永久",如下所示:
According to https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/persist you can mark a box as "persistent" as follows:
if (navigator.storage && navigator.storage.persist)
navigator.storage.persist().then(function(persistent) {
if (persistent)
console.log("Storage will not be cleared except by explicit user action");
else
console.log("Storage may be cleared by the UA under storage pressure.");
});
根据 https://developer.mozilla.org/en -US/docs/Web/API/Storage_API :
"如果将框标记为永久",则没有数据源本身或用户未专门执行操作,用户代理将不会清除内容.这包括诸如用户选择清除缓存"或清除最近的历史记录"选项.将专门询问用户删除持久性站点存储单元的权限."
但是,清除Chrome和Firefox中的近期历史记录会删除这些数据,而无需征得我的许可.我想念什么?
However, clearing recent history in Chrome and Firefox removes the data without asking me for permission. What did I miss?
推荐答案
在Chrome和Firefox中清除最近的历史记录被视为明确的用户操作".即使没有提到存储",您也应该获得一个确认对话框.普通用户甚至都不知道什么是持久存储".
Clearing recent history in Chrome and Firefox counts as an 'explicit user action'. You should get a confirm dialog, even if it does not mention 'storage'. The average user would not even know what 'persistent storage' is.
这篇关于如何使网络应用程序的数据“持久"而不是“尽力而为"?我想避免在没有足够空间的情况下清除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!