July 28, 2013

HTML5 Web storage

Currently, these are the important forms of storage systems present in the browsers.
  • Cookies
  • Web Storage
  • Indexed database API
  • Web SQL Database

Cookies:
A very tiny amount of storage used by websites to store important information. Generally, this is used to store tracking or authentication data.
Examples are
Cookie to track user’s browsing habits by third-parties
Cookies to evaluate if the user has already been logged into website

Web storage:
It’s a simple mechanism to store larger amounts of data. The CURD operations are performed over a key/value persistence system. Also known as localStorage system.

Pros
  • Really simple API.
  • Already available in all major new browsers.
Cons
  • No query language, schemas, really nothing you'd normally call a database. So it wouldn't scale well where you need to impose organization on a larger data set.
  • They didn't put transactional safety into the standard. I don't think I can sleep at night with an app running that might have race conditions and then have the risk of corrupt data.
  • Closing an app would lose the entire data. Hence, this storage mechanism can’t be used for developing HTML5 based native apps.

Indexed Database (IDB) :
IndexedDB is an API for client-side storage of significant amounts of structured data and for high performance searches on this data using indexes. IndexedDB basically provides a simple flat-file database with hierarchical key/value persistence and basic indexing.
IndexedDB provides separate APIs for synchronous and asynchronous access. The synchronous API is intended to be used only inside of Web Workers but it isn't implemented by any browser yet. The asynchronous API works both within and without Web Workers.
Pros :
  • Pretty similar to NoSQL
Cons :
  • Not yet available in most new browsers.

Web SQL Database
Web Sql is basically sqlite embedded into the browser. It's one of the most useful form of HTML5 web storage.
Pros :
  • Fast and pretty feature-rich sql implementation (besides select/insert/update/delete, you can do joins, inner selects, etc).
  • Advantageous for developing ios and Android apps as the storage persists even after the application is closed.
Cons :
  • Available in Chrome and webkit-based browsers (Safari, etc.) but not Firefox or IE.
  • The W3C Working Group has put a hold on the standard since they say they want at least two independent implementations of the standard, and there's only one so far, since everybody is using sqlite.

Useful links

No comments: