Local Storage, Session storage, Web storage, web database and cookies in HTML5

前端 未结 5 2177
闹比i
闹比i 2020-12-14 01:22

What is the difference between these concepts, and when should I use one in particular? Does this listing also contain different names for the same general concept?

相关标签:
5条回答
  • 2020-12-14 01:34

    Session Storage:Session storage is introduced where the user is carrying out a single transaction, but could be carrying out multiple transactions in different windows at the same time.Session is terminated once we close the window.

    Local Storage:Local storage is specific to domain and is introduced to span across multiple windows.There is no time limit as in the case of Cookies,and can store upto 5MB storage such as Users MailBox etc....

    0 讨论(0)
  • 2020-12-14 01:38

    HTML5 web storage is a generic umbrella term for the new client-side data storage options.

    Local Storage is persistent and scoped to the domain. At the moment two flavors are usually mentioned:

    • 'default': stores things in name/value pairs
    • Web SQL (aka Web Database): uses an SQL database

    Session Storage is non persistent and scoped only to the current window.

    Cookies are the old school way of doing all of the above. Stores name/value pairs per domain.

    0 讨论(0)
  • 2020-12-14 01:39

    I would like to add more information:
    cookies are able to store only 4k of data whereas localStorage is able to store 5mb of data (Depending on browsers)

    Websites will save cookies in browsers and next time browser will send that cookie along with http request to be used server-side. Cookies are meant for being used with the server. With localStorage, you can store more data, but it is restricted to the client by default.

    0 讨论(0)
  • 2020-12-14 01:51

    Another big thing to consider if your users are located in Europe, is that Cookies are illegal in Europe. https://www.sitepoint.com/europe-website-cookie-privacy-law/

    0 讨论(0)
  • 2020-12-14 01:53

    AFAIC:

    1. Cookies are 4k per cookie, and local storage is 5k per domain.
    2. Cookies existance time limits and sorage is just client-side protocol- and domain-specific bin for data.
    0 讨论(0)
提交回复
热议问题