Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The Storage Standard defines a common, shared storage system to be used by all APIs and technologies that store content-accessible data for individual Web sites. The Storage API gives sites' code the ability to find out how much space they can use, how much they are already using, and even control whether or not they need to be alerted before the user agent disposes of site data in order to make room for other things.
Site storage—the data stored for a Web site which is managed by the Storage Standard—includes:
window.localStorage
History.pushState()
The site storage system described by the Storage Standard and interacted with using the Storage API consists of a single site storage unit for each origin. In essence, every Web site or Web application has its own storage unit into which its data gets placed. The diagram below shows a site storage pool with three storage units within, showing how storage units can have different data types stored within and may have different quotas (maximum storage limits).
User agents are likely to use various techniques to determine the quota for various origins. One of the most likely methods—one which the specification specifically encourages, in fact—would be to consider the popularity and/or usage levels of individual sites to determine what their quotas should be. It's also conceivable that the browser might offer a user interface to customize these quotas.
The actual data storage within each site storage unit is called its box. Each site storage unit has exactly one box into which all of its data is placed, and has a box mode that describes the data retention policy for that box. There are two modes:
"best-effort"
"persistent"
"best-effort"
boxes before considering clearing a box marked "persistent"
. If it becomes necessary to consider clearing persistent boxes, the user agent will notify the user and provide a way to clear one or more persistent boxes as needed.To change an origin's box mode requires permission to use the "persistent-storage"
feature.
If the site or app has the "persistent-storage"
feature permission, it can use the StorageManager.persist()
method to request that its box be made persistent. It's also possible for the user agent to decide to make the site's storage unit persistent due to usage characteristics or other metrics. The "persistent-storage"
feature's permission-related flags, algorithms, and types are all set to the standard defaults for a permission, except that the permission state must be the same across the entire origin, and that if the permission state isn't "granted"
(meaning that for whatever reason, access to the persistent storage feature was denied), the origin's site storage unit's box mode is always "best-effort"
.
Note: See Using the Permissions API for further details about obtaining and managing permissions.
When clearing site storage units, an origin's box is treated as a single entity; if the user agent needs to clear it and the user approves, the entire data store is cleared rather than providing some means of clearing only data from individual APIs.
If a box is marked as "persistent"
, the contents won't be cleared by the user agent without either the data's origin itself or the user specifically doing so. This includes scenarios such as the user selecting a "Clear Caches" or "Clear Recent History" option. The user will be asked specifically for permission to remove persistent site storage units.
The user agent determines, using whatever mechanism it chooses, the maximum amount of storage a given site can use. This maximum is the origin's quota. The amount of this space which is in use by the site is called its usage. Both of these values are estimates; there are several reasons why they're not precise:
User agents may use any method they choose to determine the size of origins' quotas, and are encouraged by the specification to provide popular or frequently-used sites with extra space.
To determine the estimated quota and usage values for a given origin, use the navigator.storage.estimate()
method, which returns a promise that, when resolved, receives a StorageEstimate
that contains these figures. For example:
navigator.storage.estimate().then(estimate => { // estimate.quota is the estimated quota // estimate.usage is the estimated number of bytes used });
Specification | Status | Comment |
---|---|---|
Storage | Living Standard | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 55.0 |
51 (51)[1] 57 (57)[3] | ? | 42 | ? |
Persistence support | (Yes) |
55 (55)[2] 57 (57)[3] | ? | ? | ? |
Estimates support | (Yes) | 51 (51) | ? | ? | ? |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | No support | 55.0 | 51.0 (51)[1] 57.0 (57)[3] | ? | 42 | ? | 55.0 |
Persistence support | No support | (Yes) | 57.0 (57)[3] | ? | ? | ? | (Yes) |
Estimates support | No support | (Yes) | 51.0 (51) | ? | ? | ? | (Yes) |
[1] Firefox 51 introduced NavigatorStorage
, navigator.storage
, and the StorageManager.estimate()
method, as well as StorageEstimate
. These are enabled by default in nightly builds but disabled by default in all other builds. You can enable these features by setting the preference dom.storageManager.enabled
to true
. Current supported site storage includes IndexedDB and Cache API data. Web storage API data, history state information will be supported in the future release.
[2] Firefox 55 introduced StorageManager.persist()
and StorageManager.persisted()
methods. Users can also manage persistent-storage data in Preferences "Privacy and Security" -> "Site data". These are enabled by default in nightly builds but disabled by default in all other builds. You can enable these features by setting the preference dom.storageManager.enabled
and browser.storageManager.enabled to true
.
[3] The Storage API is implemented and enabled by default in Firefox 57.
navigator.storage
StorageManager
(the object returned by navigator.storage
)
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Storage_API