Web storage: Difference between revisions

Content deleted Content added
m Undid nonconstructive edits.
 
(35 intermediate revisions by 33 users not shown)
Line 3:
{{HTML}}
 
'''Web storage''', sometimes known as '''DOM storage''' ([[Document Object Model]] storage), providesis [[weba application|webstandard apps[[JavaScript]] withAPI methodsprovided andby protocols[[web forbrowser]]s. storingIt client-sideenables data.[[website]]s Web storageto supportsstore [[Persistence (computer science)|persistent]] data storage,on users' devices similar to [[HTTP cookie|cookies]], but with a greatlymuch enhancedlarger capacity<ref name="dev-opera-ws" /> and no information storedsent in the [[List of HTTP headers|HTTP request headerheaders]].<ref>{{cite web|url=http://blog.andyhume.net/localstorage-is-not-cookies|archive-url=https://web.archive.org/web/20110602165051/http://blog.andyhume.net/localstorage-is-not-cookies|url-status=dead|title=localStorage is not cookies|author-first=Andy|author-last=Hume|archive-date=2011-06-02|date=2011-03-24|access-date=2021-05-14|website=andyhume.net}}</ref> There are two main web storage types: local storage and session storage, behaving similarly to [[persistent cookie]]s and [[session cookie]]s respectively. Web Storage is standardized by the [[World Wide Web Consortium]] (W3C)<ref>{{Cite web|url=http://www.w3.org/TR/webstorage/|title=Web Storage (Second Edition)|editor-first=Ian|editor-last=Hickson|publisher=Web Platform Working Group|website=W3C|date=2021-01-28|access-date=2021-05-14}}</ref> and [[WHATWG]].,<ref>{{Cite web|url=https://html.spec.whatwg.org/multipage/webstorage.html|title=HTML Standard {{section-sign}}§ 12 Web storage|website=html.spec.whatwg.org|author=WHATWG|access-date=2021-05-14}}</ref> Alland majoris browserssupported supportby itall major browsers.
 
==Features==
Web storage differs from cookies in some key ways.
 
; ===Purpose===
: Cookies are intended for communication with servers; they are automatically added to all requests and can be accessed by both the server and client-side. Web storage falls exclusively under the purview of [[client-side scripting]]. Web storage data is not automatically transmitted to the server in every HTTP request, and a web server can't directly write to Web storage. However, either of these effects can be achieved with explicit client-side scripts, allowing for fine-tuning the server's desired interaction.
 
; ===Storage size===
: Cookies are restricted to 4 kilobytes. Web storage provides far greater storage capacity:
:* [[Opera (web browser)|Opera]] 10.50+ allows 5 MB<ref name="dev-opera-ws">{{Cite web|url=https://dev.opera.com/articles/web-storage/|title=Web Storage: Easier, More Powerful Client-Side Data Storage|author-first=Shwetank|author-last=Dixit|date=2013-03-05|access-date=2021-05-14|website=Dev.Opera}}</ref>
* [[Opera (web browser)|Opera]] 10.50+ allows 5 MB<ref name="dev-opera-ws">{{Cite web|url=https://dev.opera.com/articles/web-storage/|title=Web Storage: Easier, More Powerful Client-Side Data Storage|author-first=Shwetank|author-last=Dixit|date=2013-03-05|access-date=2021-05-14|website=Dev.Opera}}</ref>
* [[Safari (web browser)|Safari]] 8 allows 5 MB<ref name="html5rocks-quota-research">{{Cite web|url=https://www.html5rocks.com/en/tutorials/offline/quota-research/|archive-url=https://web.archive.org/web/20140201165757/https://www.html5rocks.com/en/tutorials/offline/quota-research/|url-status=dead|title=Working with quota on mobile browsers: A research report on browser storage - HTML5 Rocks|author-first=Eiji|author-last=Kitamura|publication-date=2014-01-28|access-date=2021-05-04|archive-date=2014-02-01}}</ref>
:* [[Firefox]] 34 allows 10 MB<ref name="html5rocks-quota-research"/> (formerly 5 MB per [[same-origin policy|origin]] in 2007<ref>[http://ejohn.org/blog/dom-storage/ John Resig: DOM Storage]. John Resig, ''ejohn.org''. Retrieved on 2011-06-12.</ref>)
:* [[Google Chrome]] allows 10 MB per origin (formerly 5 MB per origin)<ref>{{cite web|url=https://chromiumcodereview.appspot.com/21680002|title=Issue 21680002: Up the window.localstorage limit to 10M from 5M. - Code Review|website=Chromium Code Reviews|date=2013-03-08|access-date=2021-05-14|author=michaeln}}</ref>
:* [[Internet Explorer]] allows 10 MB per storage area<ref>{{cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bg142799(v=vs.85)|title=Introduction to Web Storage|author=Microsoft|publisher=Microsoft|website=Microsoft Docs|date=2016-10-20|access-date=2021-05-14}}</ref>
 
; ===Local and session storage===
: Web storage offers two different storage areas—local storage and session storage—which differ in scope and lifetime. Data placed in local storage is per origin—the combination of protocol, host name, and port number as defined in the [[same-origin policy]]. The data is available to all scripts loaded from pages from the same origin that previously stored the data and persists after the browser is closed. As such, Web storage does not suffer from cookie Weak Integrity and Weak Confidentiality issues, described in {{IETF RFC|6265}} sections 8.5 and 8.6. Session storage is both per-origin and per-instance (per-window or per-tab) and is limited to the lifetime of the instance. Session storage is intended to allow separate instances of the same web app to run in different windows without interfering with each other, a use case that's not well supported by cookies.<ref>[http://dev.w3.org/html5/webstorage/#introduction W3C: Web Storage draft standard]. Dev.w3.org (2004-02-05). Retrieved on 2011-06-12.</ref>
; ===Interface and data model===
: Web storage provides a better programmatic interface than cookies because it exposes an [[associative array]] [[data model]] where the keys and values are both [[String (computer science)|strings]]. An additional [[Application programming interface|API]] for accessing [[Data model|structured data]] is being considered by the W3C Web Applications Working Group.<ref>[http://www.w3.org/TR/IndexedDB/ W3C: Indexed Database API]. W3C. Retrieved on 2012-02-12.</ref>
 
==Usage==
Line 57 ⟶ 59:
 
==Web storage management==
Storage of web storage objects is enabled by default in current versions of all supporting web browsers, with browser vendors providing ways for users to natively enable or disable web storage, or clear the web storage "cache".<ref>[https://mid.as/kb/00103/enable-disable-or-clear-web-storage-cache How to enable, disable, or clear your browser's "Web Storage" cache]. mid.as. Retrieved on 2022-10-06.</ref> Similar controls over web storage are also available through 3rd party [[browser extension]]s. Each browser stores Web storage objects differently:
 
* [[Firefox]] saves Web storage objects in a [[SQLite]] file called <code>webappsstore.sqlite</code> in the user's profile folder. <ref>[https://kb.mozillazine.org/Webappsstore.sqlite Webappsstore.sqlite] kb.mozillazine.org</ref>
* [[Google Chrome]] records Web storage data in a [[SQLite]] file in the user's profile. The subfolder containing this file is "<code>\AppData\Local\Google\Chrome\User Data\Default\Local Storage</code>" on [[Microsoft Windows|Windows]], and "<code>~/Library/Application Support/Google/Chrome/Default/Local Storage</code>" on [[macOS]].
* [[Opera (web browser)|Opera]]'s Web storage is located in either "<code>\AppData\Roaming\Opera\Opera\sessions\autosave.win</code>" or "<code>\AppData\Local\Opera\Opera\pstorage\</code>" depending upon Opera's version.
* [[Internet Explorer]]'s Web storage is "<code>\AppData\LocalLow\Microsoft\Internet Explorer\DOMStorage</code>".
* [[Safari (web browser)|Safari]]'s Web Storage is located in a folder labeled "<code>LocalStorage</code>" within a hidden "<code>safari</code>" folder. <ref>[https://discussions.apple.com/thread/7772494 Where is Safari web data stored?] discussions.apple.com. Retrieved 20 2022-10-06</ref>
 
==Similar Technologies==
While localStorage is often used for storing persistent key-value pairs, other APIs have emerged to enable various use cases like iteratable indexing<ref>{{Cite web |url=https://rxdb.info/articles/localstorage.html | title=localStorage in Modern Applications | website=RxDB |access-date=August 14, 2023}}</ref> and with different performance patterns:
 
==See also==
*[[Indexed Database API]]
*[[Web SQL Database]]
*[[HTTP cookie]]
*Origin private file system (OPFS)
 
==References==