Important:
Chrome will be removing support for Chrome Apps on Windows, Mac, and
Linux. Chrome OS will continue to support Chrome Apps. Additionally,
Chrome and the Web Store will continue to support extensions on all
platforms.
Read the announcement and learn more about
migrating your app.

Managing HTML5 Offline Storage

HTML5 introduced many storage APIs that let you store a large amount of data locally in your users' browsers. But the amount of space allocated for each app is, by default, restricted to a few megabytes. Google Chrome lets you ask for a larger storage quota, beyond the previous limit of just 5 MB.

This document introduces you to the basic concepts around the types of storage used in Chrome and describes the experimental Quota Management API, which lets you manage your storage quota. The document assumes that you are already familiar with the general concepts of client-side storage and know how to use offline APIs.

Types of storage

These storage types are described in greater detail in the following sections and compared with each other in the table below.

Temporary storage

Temporary storage is transient storage that is available to any web app. Chrome automatically gives your app temporary storage, so you do not need to request allocation.

Sharing the pool

Temporary storage is shared among all web apps running in the browser.{#It is also shared across all offline APIs, such as App Cache, IndexedDB, and File System. However, it does not include web storage APIs like Local Storage and Session Storage, which still has a limit of 5 MB per origin.#} The shared pool can be up to 1/3 of the of available disk space. Storage already used by apps is included in the calculation of the shared pool; that is to say, the calculation is based on (available storage space + storage being used by apps) * .333 .

Each app can have up to 20% of the shared pool. As an example, if the total available disk space is 60 GB, the shared pool is 20 GB, and the app can have up to 4 GB. This is calculated from 20% (up to 4 GB) of 1/3 (up to 20 GB) of the available disk space (60 GB).

Asking for more space

Although you can query for the amount of storage space available for your app and the amount of data already stored for your app, you cannot ask for more temporary storage space. If an app exceeds the allocated quota, an error is thrown.

Running out of storage

Once the storage quota for the entire pool is exceeded, the entire data stored for the least recently used host gets deleted. The browser, however, will not expunge the data in LocalStorage and SessionStorage. For data stored in other offline APIs, the browser deletes the data in whole and not in part so that app data doesn't get corrupted in unexpected ways.

As each app is limited to a maximum of 20% of the storage pool, deletion is likely only if the user is actively running more than five offline apps that are each using the maximum storage.

However, available storage space can shrink as users add more files on their hard drives. When the available disk space gets tight (Remember, the shared pool only gets half of the current available disk space), the browser deletes all the data stored for the least recently used host.

Persistent storage

Persistent storage is storage that stays in the browser unless the user expunges it. It is available only to apps that use the File System API, but will eventually be available to other offline APIs like IndexedDB and Application Cache.

An application can have a larger quota for persistent storage than temporary storage, but you must request storage using the Quota Management API and the user must grant you permission to use more space. Chrome presents an info bar that prompts the user to grant the app more local storage space.

Unlimited storage

Unlimited storage is similar to persistent storage, but it is available only to Chrome apps and extensions (.crx files). The size of unlimited storage is limited only by the availability of space in the user's hard drive. You can ask for the unlimitedStorage permission in the manifest file for an app or extension. At installation, the user is informed of permissions required by the app or extension. By proceeding with the installation, the user implicitly grants permission for all pages whose URLs are listed in the manifest.json file.

To learn more, see the respective developer guides for apps and extensions.

You can ask for the unlimitedStorage permission in the manifest file for the app or extension.

User experience at first use

Invisible to the user. The app just runs.

Chrome displays an info bar that prompts the user to either accept or decline the storage request.

But if the amount of quota you request is actually less than the app's current allocation, no prompt is shown. The larger quota is kept.

At installation, the user is informed of permissions required by the app or extension. By proceeding with the installation, the user implicitly grants permission for all pages whose URLs are listed in the manifest.json file for app or extension.

User experience at subsequent requests for increased storage

Not applicable. You cannot ask for more temporary storage.

Chrome prompts the user again.

Chrome does not prompt the user after installation, regardless of the requests for increased quota by the app or extension.

Persistence of data

Transient. The browser can delete the data.

Persistent. The browser doesn't delete the data unless the user instructs it to. Data is available in subsequent accesses.

Do not assume that the data is permanent, because the user can delete it.

Same as persistent storage.

Default storage space

Up to 20% of the shared pool.

0 MB. You have to explicitly ask for a specific storage space.

0 MB. You have to explicitly ask for unlimitedStorage in the manifest file.

If you do not specify your storage requirements, Chrome allocates storage to the app from the shared pool of temporary storage.

Maximum storage space

Up to 20% of the shared pool.

As large as the available space on the hard drive. It has no fixed pool of storage.

Querying storage usage and availability

To query the storage size that is being used and the available space left for the host, call queryUsageAndQuota() with the following:

Type of storage you want to check

Success callback

The usage reported by the API might not match with the actual size of the user data, as each storage might need some extra bytes to store its metadata. Also, status updates can lag, resulting in the API not reflecting the most recent storage status.

If you want to ask for the status of persistent storage, simply replace webkitStorageInfo.TEMPORARY with webkitStorageInfo.PERSISTENT. The enum is also in the window object (global namespace), so you can also use window.PERSISTENT and window.TEMPORARY.

Asking for more storage

You don't need to ask for more temporary storage as the allocation is automatic, and you can't get beyond the maximum limit (as described in the table).

For persistent storage for File System API, the default quota is 0, so you need to explicitly request storage for your application. Call requestQuota() with the following:

Type of storage

Size

Success callback

Depending on what you ask for, the following happens:

If you ask for a larger quota, the browser presents an info bar to the user and prompts them to either grant or deny permission for increased quota. In some cases, the request might be silently rejected, and the current quota or smaller quota is returned.

If the amount of quota you request is less than the app's current allocation, no prompt is shown.

If you ask for more storage than what is allowed, you get an error (QUOTA_EXCEEDED_ERR).

If you call requestQuota() again after the user has already granted permission, nothing happens. So don't bother calling the method again.

requestQuota

Ask for more storage. The browser presents an info bar to prompt user to grant or deny the app the permission to have more storage.

// you could also use it from webkitTemporaryStorage
navigator.webkitPersistentStorage.requestQuota (
newQuotaInBytes,
quotaCallback,
errorCallback);

Parameters

newQuotaInBytes

The amount of bytes you want in your storage quota.

successCallback

Optional callback that passes the amount of bytes granted.

errorCallback

Optional error callback.

Future development

The plan is to put all HTML5 offline storage APIs—including IndexedDB, Application Cache, File System,{# LocalStorage, SessionStorage,#} and other APIs that might be specified—under the Quota Management API. You will be able to manage all storage allocation with it.