SessionStorage and LocalStorage
- SessionStorage is used to store data in a session locally, which can only be accessed by pages in the same session and is destroyed when the session ends. Therefore, sessionStorage is not a persistent local storage, only session level storage. And LocalStorage for persistent LocalStorage, unless actively delete data, otherwise the data is never expired.
WebStorage and cookie differences
- WebStorage is similar in concept to cookie, except that it is designed for larger storage capacity. Cookie size is limited, and every time you request a new page when the Cookie will be sent in the past, so virtually wasted broadband, in addition to Cookie also need to specify the scope, can not be called across the domain.
- In addition, with setItem WebStorage, the getItem, removeItem, methods of the clear, don’t like cookies need to encapsulate setCookies front-end developer himself, getCookie. However, cookies are also indispensable: the function of cookies is to interact with the server, as part of the HTTP specification and exist, and WebStorage is only for the local “storage” of data.