Get to know MDN better
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Note: This feature is available in Web Workers.
The Content Index API allows developers to register their offline enabled content with the browser.
As it stands, offline web content is not easily discoverable by users. Content indexing allows developers to tell the browser about their specific offline content. This allows users to discover and view what is available, whilst giving developers the ability to add and manage this content. Examples could be a news website prefetching the latest articles in the background, or a content streaming app registering downloaded content.
The Content Index API is an extension to service workers, which allows developers to add URLs and metadata of already cached pages, under the scope of the current service worker. The browser can then use these entries to display offline reading to a user. As a developer you can also display these entries within your application.
Indexed entries do not automatically expire. It's good practice to present an interface for clearing out entries, or periodically remove older entries.
Note: The API supports indexing URLs corresponding to HTML documents. A URL for a cached media file, for example, can't be indexed directly. Instead, you need to provide a URL for a page that displays media, and which works offline.
Provides functionality to register content available offline.
ContentIndexEventDefines the object used to represent the contentdelete event.
The following additions to the ServiceWorker have been specified in the Content Index API spec to provide an entry point for using content indexing.
ServiceWorkerRegistration.index Read onlyReturns a reference to the ContentIndex interface for indexing cached pages.
contentdelete eventFired when content is removed by the user agent.
All the following examples assume a service worker has been registered. For more information see the Service Worker API.
Here we get a reference to the ServiceWorkerRegistration, then check for the index property, which gives us access to the content index interface.
Here we're declaring an item in the correct format and creating an asynchronous function which uses the add() method to register it with the content index.
The below example shows an asynchronous function that retrieves items within the content index and iterates over each entry, building a list for the interface.
Below is an asynchronous function, that removes an item from the content index.
All the above methods are available within the scope of the service worker. They are accessible from the WorkerGlobalScope.self property:
When an item is removed from the user agent interface, a contentdelete event is received by the service worker.
The contentdelete event is only fired when the deletion happens due to interaction with the browser's built-in user interface. It is not fired when the ContentIndex.delete() method is called.
| Content Index |
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
This page was last modified on Aug 29, 2024 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.