Showing posts with label Local Storage. Show all posts
Showing posts with label Local Storage. Show all posts

Monday, March 13, 2017

What is the difference between Local Storage and Cookies

Hi Friends,

In this post we are going to talk about when to use Local storage and Cookies.

To begin with, this is an extremely broad scope question, and a lot of pros/cons will be contextual to the situation.

Please find the below differences.


Local Storage
Cookies
Good to store large amount of data, up to 4MB
Good for small amount of data.
Cookies give you a limit of 4096 bytes (4095, actually) per cookie
Local Storage allow you to store JavaScript primitives but not Objects or Arrays (it is possible to JSON serialize them to store them using the APIs)
Cookies only allow you to store strings
Local storage data is not sent to the server on every request (HTTP header) as it is purely at the client side
All data is transferred to and from server, so bandwidth is consumed on every request
It stores data with no expiration date, and gets cleared only through JavaScript, or clearing the Browser Cache / Locally Stored Data
Can specify timeout period so that cookies data are removed from browser
Local storage stores the data in the form of key and value

Not supported by anything before: IE 8, Firefox 3.5, Safari 4, Chrome 4, Opera 10.5, iOS 2.0, Android 2.0
local storage can only be read client-side



Hope this helps...

Popular Posts