Monday, March 9, 2015

WebStorage fallback

http://caniuse.com/#search=webstorage shows WebStorage is well supported across browsers, but modern browsers support private browsing mode and the implementation is quite different with regarding to WebStorage support. For example, Chrome is doing a very smart logic - support localStorage and sessionStorage, but stores the data in a temp folder. On the other hand, Safari is doing a dumb logic - disable storage APIs in private browsing mode.

Nowadays Web developers don't need to worry about IE6 any more, but need to think of private browsing experience. As to writing, most browsers have private browsing mode though their names are slightly different.

IE: InPrivate browsing
Firefox: New Private window
Safari: New Private window
Chrome: Incognito window

To better support private browsing mode, we need fallback (just like we did for old browsers or new ES6 features). Googled for some time and found cookie is one possible solution to fallback Storage APIs.

https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills
https://gist.github.com/remy/350433
http://stackoverflow.com/questions/4692245/html5-local-storage-fallback-solutions
https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

It works in some cases, but cookie has issues:
1. cookie value has size limit
2. cookie is shared across tab/windows
3. cookie has http overhead
4. cookie has security issues
5. cookie value is string instead of JSON

No comments:

Post a Comment