ContentIndex: delete() 方法

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

注意:此功能在 Web Workers 中可用。

ContentIndex 接口的 delete() 方法用于取消索引中某个条目的注册。

注意: 调用 delete() 只会影响索引。它不会从 Cache 中删除任何内容。

语法

js
delete(id)

参数

id

您希望 ContentIndex 对象移除的已索引内容的唯一标识符。

返回值

返回一个解析为 undefinedPromise

异常

不会抛出任何异常。

示例

下面是一个异步函数,它从 内容索引 中移除一个条目。我们接收当前 ServiceWorkerRegistration 的引用,这使我们能够访问 index 属性,从而访问 delete 方法。

js
async function unregisterContent(article) {
  // reference registration
  const registration = await navigator.serviceWorker.ready;

  // feature detect Content Index
  if (!registration.index) return;

  // unregister content from index
  await registration.index.delete(article.id);
}

delete 方法也可以在 Service Worker 作用域内使用。

js
self.registration.index.delete("my-id");

规范

规范
Content Index
# content-index-delete

浏览器兼容性

另见