sessionStorage
i localStorage
are data containers, provided to application by browser. It holds data in text format as a key/value pairs. It's size depends on browser.
They share same API:
setItem(key, value)
- ustawia wartośćvalue
pod kluczemkey
getItem(key)
- zwraca wartość spod kluczakey
removeItem(key)
- usuwa wartość spod kluczakey
clear()
- czyści pamięć.
Differences:
Session Storage:
- Cleared on closing tab/browser
- About 5MB memory
- Is not shared between browser's tabs, even if they are under same domain
Local Storage:
- It's not cleared automatically - it has to be cleared manually in devtools, in browser's settings or from code
- About 5-10MB memory
- Browser's tab share it if they are under same domain