The difference between 2.javascript cache localstorage and Sessionstorage

Source: Internet
Author: User
Tags sessionstorage

2018-08-04 Preface this question when doing the project today, how to change the login link to the user name after the user login is successful

Solution: OnLoad Load event with Sessionstorage cache and JS

After the user has successfully logged in, use the cache, set the user name to the cache, and then get it when each page loads.

The difference between Localstorage and sessionstoragecommon: All are stored in the browser side, and the same Origindifference: : 1, Sessionstorage and localstorage do not automatically send data to the server, only locally saved. ’
2, Sessionstorage and Localstorage although there is a storage size limit, but much larger than the cookie, can reach 5M or greater
3. Data validity is different, Sessionstorage: only valid until the current browser window is closed; localstorage: Always valid, window or browser Close is also saved, so it is used as persistent data;
4, the scope is different, sessionstorage is not shared in different browser windows, even the same page; localstorage are shared across all homologous windows;
5, the Web Storage support event notification mechanism, you can send the notification of data updates to the listener
6, the Web Storage API interface to use more convenient. Reference Links: the difference between a Cookie, a session and a localstorage, and a sessionstorage

2.javascript The difference between the cache localstorage and Sessionstorage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.