![]() |
What is the difference between local storage and cookies?
Hello friends i want to know What is the difference between local storage and cookies?
|
[B]Cookies[/B
Pros: Legacy support (it's been around forever) Persistent data Expiration dates Cons Each domain stores all its cookies in a single string, which can make parsing data difficult Data is unencrypted, which becomes an issue because...... though small in size, cookies are sent with every HTTP request Limited size (4KB) SQL injection can be performed from a cookie Local storage Pros Support by most modern browsers Persistent data that is...... stored directly in the browser Same-origin rules apply to local storage data Is not sent with every HTTP request ~5MB storage per domain (that's 5120KB) Cons Not supported by anything before: IE 8 Firefox 3.5 Safari 4 Chrome 4 Opera 10.5 iOS 2.0 Android 2.0 |
Cookies and local storage serve different purposes. Cookies are primarily for reading server-side, local storage can only be read client-side. So the question is, in your app, who needs this data — the client or the server?
If it's your client (your JavaScript), then by all means switch. You're wasting bandwidth by sending all the data in each HTTP header. If it's your server, local storage isn't so useful because you'd have to forward the data along somehow (with Ajax or hidden form fields or something). This might be okay if the server only needs a small subset of the total data for each request. You'll want to leave your session cookie as a cookie either way though. As per the technical difference, and also my understanding: Apart from being an old way of saving data, Cookies give you a limit of 4096 bytes (4095, actually) - its per cookie. Local Storage is as big as 5MB per domain - SO Question also mentions it localStorage is an implementation of the Storage Interface. It stores data with no expiration date, and gets cleared only through JavaScript, or clearing the Browser Cache / Locally Stored Data - unlike cookie expiry. |
Local storage:
1. Local storage stores the data in the form of key and value 2. The data is stored for longer duration and remains in the browser unless the user deletes it explicitly, it remains even after a computer restart. 3. No way to specify the timeout period as the Cookies have. 4. Good to create an offline application that runs on the client machine (browser). 5. Easy to work with the JavaScript. 6. Local storage data is not sent to the server on every request (HTTP header) as it is purely at the client side. Cookies : 1. Good for small amount of data 2. Difficult to work with JavaScript 3. All data is transferred to and from server, so bandwidth is consumed on every request 4. Can specify timeout period so that cookies data are removed from browser |
Local storage
- Local storage stores the data in the form of key and value - The data is stored for longer duration and remains in the browser unless user delete it explicitly, it remains even after computer restart - No way to specify the time out period as the Cookies have - Good to store large amount of data, up to 4MB Cookies - Good for small amount of data - Difficult to work with JavaScript - All data is transferred to and from server, so bandwidth is consumed on every request |
Local storage is good to create an offline application that runs on the client machine.
Cookies are good for small amount of data and tough to work with JavaScript. |
Cookies are primarily for reading server-side, localStorage can only be read client-side.
Cookies allow you to store string only while using local storage you can store JavaScript but not object or array. |
local storage stores large amount of data and cookies stores small amount of data
|
Cookies data store temporarily and local stroage data store user can delete the information itself...
|
Local storage:
1. Local storage stores the data in the form of key and value 2. The data is stored for longer duration and remains in the browser unless the user deletes it explicitly, it remains even after a computer restart. 3. No way to specify the timeout period as the Cookies have. Cookies : 1. Good for small amount of data 2. Difficult to work with JavaScript 3. All data is transferred to and from server, so bandwidth is consumed on every request 4. Can specify timeout period so that cookies data are removed from browser |
Quote:
Hi, very important information thanks for sharing. |
All times are GMT -7. The time now is 12:56 AM. |
Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.