11

With new Html 5 there are 3 main ways to store data in your browser:

  • localStorage
  • WebSQL DB
  • Indexed DB

I wanted to know, for each of the types, for how long data is stored? If the user enters the day after, the data will still be there? after one month? and one year?

Thanks

Mateu
  • 2,636
  • 6
  • 36
  • 54
  • All three are persistent unless user wipes them. For differences have a look [here](http://csimms.botonomy.com/2011/05/html5-storage-wars-localstorage-vs-indexeddb-vs-web-sql.html). – kubetz Dec 19 '11 at 16:20
  • For all 3, there is no programmatic way to expire...It is entirely upto the user.. There is a really good tutorial on HTML5 Local Storage at http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8 – Diana Dec 22 '11 at 13:28

2 Answers2

7

The most correct answer to this question is: You don't know.

The user could wipe his/her local data at any time, and any type of local storage is subject to user preferences and to be considered extremely volatile. However, there is no defined expiration time, according to Web Storage specifications:

Expiring stored data

User agents may, if so configured by the user, automatically delete stored data after a period of time.

For example, a user agent could be configured to treat third-party local storage areas as session-only storage, deleting the data once the user had closed all the browsing contexts that could access it.

This can restrict the ability of a site to track a user, as the site would then only be able to track the user across multiple sessions when he authenticates with the site itself (e.g. by making a purchase or logging in to a service).

However, this also reduces the usefulness of the API as a long-term storage mechanism. It can also put the user's data at risk, if the user does not fully understand the implications of data expiration.

Source: http://dev.w3.org/html5/webstorage/

Anders Marzi Tornblad
  • 18,896
  • 9
  • 51
  • 66
4
  • WebSQL is deprecated. See here.
  • Indexed DB is persistent.
  • localStorage is also persistent (not to be confused with sessionStorage).

'Persistent' comes with the caveat that atornblad pointed out: it's only persistent until the user decides to wipe their own data.

Steve Blackwell
  • 5,904
  • 32
  • 49
  • 5
    WebSQL is deprecated, but at the current moment there is nothing that replaces it. So... – Mateu Dec 19 '11 at 16:42
  • Indeed, it's only deprecated because people quickly united behind a single solution (sqLite), which made proceeding with a formal standard seem redundant. PhoneGap and many other significant platforms thus continue to rely on WebSQL, and it doesn't seem to be going anywhere. – XML Dec 13 '12 at 22:17