6 ms·
localStorage is pretty much only thing we need these days.
by homakov 10y ago
localStorage is pretty much only thing we need these days.
- marcuswestin 10y agoAlmost! Except if you want to store objects/arrays/numbers (localStorage only supports strings), or want your site to work in Safari Private mode (where localStorage breaks), or if you have to support legacy environments with old browsers (like many government services), etc etc etc :)
- diggan 10y agoNot that I disagree with your other arguments but this one sticks out: > Except if you want to store objects/arrays/numbers (localStorage only supports strings) My normal usage of localStorage usually looks like this: const getItem = (item) => { JSON.parse(window.localStorage.getItem(item)) } // and const setItem = (item, val) { window.localStorage.setItem(item, JSON.stringify(val)) } And then you won't have issues with any type.
- marcuswestin 10y agoExcept when a value has already been stored previously without JSON.stringify (in which case JSON.parse will throw), or you need a default value if unset (e.g `store.get('username', 'anonymous')`, or ... :) But I also see your point that sometimes the very quick and simple solution can be useful!
- IMTDb 10y agoNot if you want to store more than few MB (5 or 10 max depending of browsers if I recall). Not if you want/need an async API. Not if you need to be able to search your storage.
- joantune 10y agoYup on all accounts, although: > Not if you want to store more than few MB (5 or 10 max depending of browsers if I recall) There's a case for something like http://pieroxy.net/blog/pages/lz-string/index.html http://pieroxy.net/blog/pages/lz-string/index.html which can save up a lot of space
- marcuswestin 10y agoLet's create a plugin that automatically does compression!
- marcuswestin 10y agoCreated issue: https://github.com/marcuswestin/store.js/issues/183 https://github.com/marcuswestin/store.js/issues/183 Will tackle a bit down the road.