我想详细了解我正在开发的网络应用程序占用了多少存储空间。更具体地说,我对存储在 indexedDB 中的数据大小感兴趣。
我知道我可以使用
navigator.storage.estimate()
来获取总值,但即使数据库为空,它也会显示超过 1 MB,而且我有兴趣具体了解 indexedDB 的大小。
有办法检查尺寸吗?
navigator.storage.estimate().usageDetails
提供按存储类型的细分,但 Firefox/Safari 不支持(请参阅浏览器兼容性)注意:返回的值并不精确:出于安全原因,在压缩、重复数据删除和混淆之间,它们将不精确。
是的,您可以使用配额管理API来获取这些信息。这是一项实验性功能,目前 EDGE 不支持
这个网站将为您提供浏览器如何支持此功能并可以真实看到的信息
示例
// Query current usage and availability in Temporary storage:
navigator.storageQuota.queryInfo("temporary").then(
function(storageInfo) {
// Continue to initialize local cache using the obtained
// usage and remaining space (quota - usage) information.
initializeCache(storageInfo.usage,
storageInfo.quota - storageInfo.usage);
});
更多阅读内容请访问 W3org