Cookie, LocalStorage, SessionStorage - jellyfish-tom/TIL GitHub Wiki
[SOURCES]
SessionStorage, LocalStorage and Cookies all are used to store data on the client side. Each one has its own storage and expiration limit.
1. LocalStorage
- localStorage stores data forever in the browser
- localStorage is preserved on client side only
- localStorage capacity is 5MB
- localStorage works on same-origin policy. So, data stored will only be available on the same origin.
2. SessionStorage
- sessionStorage expires when the browser closes (not the tab)
- sessionStorage is preserved on client side only
- sessionStorage is only available in window/tab it was created in
- sessionStorage works on same-origin policy. So, data stored will only be available on the same origin.
3. Cookie
- cookie stores data that has to be sent back to the server with subsequent requests.
- cookie expiration time is configurable.
- cookie is sent to/from server in header of HTML request.
- cookie size limit is 4K. It is for the entire cookie, including name, value, expiry date etc. To support most browsers, keep the name under 4000 bytes, and the overall cookie size under 4093 bytes.