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

5

29

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?

  • HTML5 local storage
  • HTML5 session storage
  • HTML5 web storage
  • HTML5 web database
  • Cookies
Debug answered 22/3, 2011 at 22:23 Comment(0)
P
43

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.

Printing answered 22/3, 2011 at 22:34 Comment(1)
It's worth noting that the only one of these that is guaranteed to work cross-browser is cookies, and cookies are not suitable for storing more than a small amount of data. For example, IE and Firefox will not be implementing Web SQL because of how tightly it's bound to SQLite (meaning it's hard to write a specification without also specifying SQLite).Concertize
K
3

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.

Kirin answered 11/10, 2012 at 18:31 Comment(0)
R
1

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

Rockbound answered 19/12, 2013 at 6:3 Comment(0)
D
0

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.
Detestation answered 23/2, 2015 at 7:1 Comment(0)
I
-3

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/

Insurance answered 18/10, 2016 at 23:49 Comment(1)
From the article: "The specific technology is not important. While cookies are an obvious target, the law applies to client-side storage, Flash cookies, image trackers, browser fingerprinting or any technology used to identify an individual." Gist of the law is: you just shouldn't track individuals without their consent. Cookies are perfectly fine, as long as they are functional for the end-use itself.Maximilien

© 2022 - 2024 — McMap. All rights reserved.