Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantage of SessionStorage over Cookie

Q1-> What are the advantage of SessionStorage/LocalStorage over Cookie ?

Q2-> A Value stored by xyz site can be viewed or edited by any other site or the user ?

like image 930
Sourav Avatar asked May 12 '11 03:05

Sourav


2 Answers

1) Session Storage and Local Storage allow for a greater capacity (currently 5mb with most browsers), and are not sent back to the server for every HTTP request (HTML, images, JavaScript, CSS, etc) - reducing the amount of traffic between between client and server (saving you $dosh).

2) Local / Session Storage are both restricted to the domain setting/getting the values, so if you use localStorage.set('key', 'val') on www.domain1.com, you cannot access that data using localStorage.get('key') on www.domain2.com. Bear in mind the restriction also applies to domains and subdomains - i.e. you cannot access www.domain1.com local/session storage from sub.domain1.com either.

Update from @josh3736: users, however, have full access to the raw local and session storage. This is how users are currently able to unlock all levels on the web version of Angry Birds: http://wesbos.com/all-levels-html5-angry-birds/ - to reiterate Josh, never trust data at the client tier.

More details here: http://diveinto.html5doctor.com/storage.html

like image 75
Matty F Avatar answered Sep 30 '22 14:09

Matty F


Another advantage of using Session Storage its performance in using it. Especially for large data (100kb,etc). Simple cookies would have to be a part of each request to the server. So you won't get this stored data to the server by simple means, but I can libe with that.

like image 21
catalinux Avatar answered Sep 30 '22 13:09

catalinux