我可以查看我的 indexedDB 占用了多少 space 吗?

Can I check how much space my indexedDB is taking up?

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

我知道我可以使用 navigator.storage.estimate() 来获得总值,但它显示超过 1 兆字节,即使是空数据库,我有兴趣具体了解 indexedDB 的大小。

有没有办法检查尺寸?

是的,您可以使用 配额管理 API 来获取这些信息。这是一项实验性功能,目前 EDGE 不支持

This 站点将向您提供有关浏览器如何支持此功能以及如何实际查看的信息

示例

// 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

中阅读更多内容

目前没有标准(甚至非标准)API按类型提供存储使用情况的细分。

  • 在 Chrome 的 DevTools 中,“应用程序”选项卡按类型提供存储细分;单击左上角的 "Clear storage" 视图,应该会出现一个图表。这对于本地调试很有用,但不了解存储使用"in the wild"

  • https://github.com/whatwg/storage/issues/63

  • 上有一些关于使用此数据扩展 navigator.storage.estimate() 的讨论

更新:navigator.storage.estimate() 现在按存储类型提供细分(在 Chrome 75 及更高版本中)。