我可以检查我的indexedDB占用了多少空间吗?

问题描述 投票:0回答:2

我想详细了解我正在开发的网络应用程序占用了多少存储空间。更具体地说,我对存储在 indexedDB 中的数据大小感兴趣。

我知道我可以使用

navigator.storage.estimate()
来获取总值,但即使数据库为空,它也会显示超过 1 MB,而且我有兴趣具体了解 indexedDB 的大小。

有办法检查尺寸吗?

browser storage indexeddb
2个回答
19
投票

注意:返回的值并不精确:出于安全原因,在压缩、重复数据删除和混淆之间,它们将不精确。


  • Chrome DevTools 中,Application 选项卡按类型提供存储细分;单击左上角的“清除存储”视图,应该会出现一个图表。这对于本地调试很有用,但不了解“野外”的存储使用情况

-1
投票

是的,您可以使用配额管理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

© www.soinside.com 2019 - 2024. All rights reserved.