angular-webstorage icon indicating copy to clipboard operation
angular-webstorage copied to clipboard

Is LocalStorage always supported?

Open hasdavidc opened this issue 13 years ago • 2 comments

Just wondering - is localStorage always supported, since a fallback document.cookie implementation is provided if !window.localStorage:

https://github.com/fredricrylander/angular-webstorage/blob/master/angular-webstorage.js#L534-L576

If this actually is the case, I'd suggest replacing the 'memory' storage type with a new 'cookie' type, if document.cookie is always accessible (I'm not sure whether it is or not).

hasdavidc avatar Jul 29 '13 21:07 hasdavidc

Unfortunately no. Since all browsers allow their users to turn cookies off, and supposedly some users do, we cannot count on cookie support always being there. And some browsers, e.g. Chrome, actually use one and the same setting for switching both local storage and cookies on or off at the same time.

The cookie fallback's job is to polyfill the local storage feature into older browsers, e.g. IE < 8. The cookie support still needs to be switched on for it to work though.

And here's where 'memory' comes into play. The in-memory engine is the fallbacks of fallbacks for this module, only meant to kick in as a very last aid for your app. But as said in the documentation: "NOTE: The in-memory storage should really be seen as a last resort since all its values will be lost on page reload (somewhat negating the whole idea of client web storage!)"

fredricrylander avatar Jul 30 '13 09:07 fredricrylander

Thanks for the explanation - was helpful to my understanding.

hasdavidc avatar Jul 30 '13 20:07 hasdavidc