Web storage
Web storage (also called DOM storage or inaccurately known as supercookie ) is a web application technology that stores data in a web browser . DOM Storage supports persistent data storage, similar to cookies , as well as local ( Local Storage ) and session-specific storage ( Session Storage ). It is the place where the Flash Cookies (or Local Shared Objects , LSOs for short ) are stored.
DOM storage is standardized by the World Wide Web Consortium (W3C). It was originally part of the HTML5 specification, but has since been spun off into its own specification.
features
In simplified terms, DOM Storage can be viewed as a further development of cookies ("super cookies"). The technology offers much larger storage capacity (5 MB per domain in Firefox, approx. 10 MB per storage area in Internet Explorer) and better development interfaces . However, it differs from cookies in some ways.
Client-side interface
In contrast to cookies, which both the server and the client can access, DOM Storage is completely controlled by the client. Data is not transferred to the server with every HTTP request, and a web server cannot write data directly to the DOM storage either. Access is only possible via scripts on the website.
storage
DOM Storage offers two different types of storage: local (localStorage) and session-specific (sessionStorage). They differ in terms of scope and duration.
Local storage
Data that is stored locally, so-called Local Shared Objects (LSO), are linked to a domain and the local user profile of the access computer and remain in place even after the browser is closed. All scripts of a domain from which the data was saved can access the user profile-specific data.
In Mozilla Firefox, the data is saved in the webappsstore.sqlite database file. The SQLite 3 file can be viewed with a suitable program . There are browser add-ons that were created for the purpose of having this data deleted from the system again, also automatically, e.g. B. with Better Privacy . By entering “about: config” in the address line, the value of dom.storage.enabled can be changed from true to false , and DOM storage objects can thus be switched off.
Session-specific storage
Session-specific data stored are linked to and limited to the browser window. Saved data is deleted when the browser window is closed. This technology offers the possibility of running several instances of the same application in different windows without influencing one another, which is not supported by cookies.
Data model
DOM Storage stores data in an associative array in which the keys and values are strings . An additional programming interface for access to structured data, possibly on an SQL basis, is currently being discussed within the W3C's Web Applications Working Group.
use
Data can be saved and read out again using the setItem and getItem functions .
localStorage
// Speichert ein Key-Value-Paar im localStorage
// Die Daten können auch nach einem Neustart des Browsers ausgelesen werden
localStorage.setItem('key', 'value');
// Liest den eben gespeicherten Wert aus und zeigt ihn an
alert(localStorage.getItem('key')); // value
sessionStorage
// Speichert ein Key-Value-Paar im sessionStorage
// Die Daten werden nach dem Schließen des Browsers gelöscht
sessionStorage.setItem('key', 'value');
// Liest den eben gespeicherten Wert aus und zeigt ihn an
alert(sessionStorage.getItem('key')); // value
Saving JSON objects
Only strings can be stored in web storages. However, if a JSON object is to be saved, it must be converted into a string before saving. When reading it out, it can then be converted back into a JSON object.
localStorage.setItem('key', JSON.stringify({firstname: 'Peter', lastname: 'Meier'}));
alert(JSON.parse(localStorage.getItem('key')).firstname); // Peter
Browser support
Web storage is supported by the following browsers:
Browser | from version |
---|---|
Google Chrome | 4th |
Mozilla Firefox | 3.5 |
Opera | 10.5 |
Internet Explorer | 8th |
Edge | 12 |
Apple Safari | 4th |
iOS | 3.2 |
Android | 2.1 |
Similar technologies
- HTTP cookies
- Indexed Database API
- Local shared objects in Adobe Flash
- Google Gears for IE, Firefox, Apple Safari and Windows Mobile
- Application cache
Web links
- W3C: Web Storage
- Web Tracking Report 2014 Fraunhofer Institute for Secure Information Technology SIT Markus Schneider, Matthias Enzmann, Martin Stopczynski, Eds. Michael Waidner Fraunhofer Verlag PDF 118 pages ISBN 978-3-8396-0700-8
Individual evidence
- ↑ Web Storage Specification of the W3C (World Wide Web Consortium)
- ^ John Resig: DOM Storage
- ↑ Introduction to Web Storage. Microsoft , October 20, 2006, accessed July 1, 2019 .
- ^ W3C: Web Storage draft standard
- ^ W3C: Web Storage draft standard
- ↑ http://www.html5rocks.com/en/features/storage
- ↑ https://developer.mozilla.org/de/docs/Web/API/Window/localStorage