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

吃可爱长大的小学妹 提交于 2019-11-28 19:12:10
DA.

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.

Arun

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.

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....

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.

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!