Web Storage: easier, more powerful client-side data storage

Forums » Dev.Opera » Archived Article Discussions

This topic has been closed. No new entries allowed.

Reason: You can now post comments on articles on Dev Opera

Forum rules and guidelines

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

2. March 2010, 07:02:00

Opera Software

shwetankdixit

Opera Software

Posts: 49

Web Storage: easier, more powerful client-side data storage

This article covers Web Storage, a new W3C specification supported in Opera 10.50+ that allows data to be saved on the client-side in a much more powerful, more secure fashion than before. Here Shwetank Dixit discusses both facets of Web Storage - Local Storage and Session Storage - and how to use them to store web application data on the client, along with some simple examples to get you started.

( Read the article )

2. March 2010, 21:45:56

tomassplatch

Posts: 79

is this specification capable of replacing google gears plugin? I mean, 5 mb of storage is not that much for an offline gmail. Also, does the structure of the data (sql?) allow for running web apps offline?

2. March 2010, 21:52:41

Frenzie

Posts: 14438

Originally posted by tomassplatch:

is this specification capable of replacing google gears plugin? I mean, 5 mb of storage is not that much for an offline gmail. Also, does the structure of the data (sql?) allow for running web apps offline?

I think this is only part of what Gears did. Do you know anything about the data limits of Gears?
Intelligent alien life does exist, otherwise they would've contacted us. — CalendarExtend Opera

2. March 2010, 22:27:15

POWRSURG

Posts: 18

Maybe I'm just too rigid minded for this, but what exactly is so useful with this? Everything that I think of that might benefit from it is better off being remembered by the server and thus can handle older browsers that do not support these features. Is it mostly only useful for offline applications?

3. March 2010, 12:45:07

Opera Software

shwetankdixit

Opera Software

Posts: 49

@powersurg: Yes, it will be really usefull for offline apps, especially localStorage. Session storage can be very usefull in sites like amazon where people might be conducting different transactions from the same site in two different tabs, and data from one tab might 'flow' into the other tab because of the way cookies are used. Session storage will be per page, so that scenario will not happen.

It also allows easier storage of data than cookies, and in much greater amount too.

4. March 2010, 11:24:05

brucelawson

Posts: 52

Gears isn't completely superseded by browser storage. But most of its use cases are.

Google said in a blogpost called "Hello HTML5" http://gearsblog.blogspot.com/2010/02/hello-html5.html

"we've shifted our effort towards bringing all of the Gears capabilities into web standards like HTML5. We're not there yet, but we are getting closer. In January we shipped a new version of Google Chrome that natively supports a Database API similar to the Gears database API, workers (both local and shared, equivalent to workers and cross-origin wokers in Gears), and also new APIs like Local Storage and Web Sockets. Other facets of Gears, such as the LocalServer API and Geolocation, are also represented by similar APIs in new standards"

5. March 2010, 03:02:00

edvakf

Posts: 762

Web SQL Storage is VERY good for Opera Unite because File API doesn't have a transaction. Thanks Opera for implementing it.

25. March 2010, 16:23:50

triplezero

Posts: 7

Why link to the W3 spec if you're not even going to bother to implement it?

I just wasted an hour of my time before figuring out that Opera localStorage is not capable of storing arbitrary values but casts them to strings first!

The specs say that the *keys* are string, but the values can be *any* object to be stored using a special clone algorithm.

Without being able to store structured data like arrays and dicts, this is really not of much use. Anyone know if Opera got a built-in JSON coder? Or do they expect us to go messing about with String.split and Array.join ...

25. March 2010, 20:16:37

Frenzie

Posts: 14438

You could try http://code.google.com/p/realstorage/

I assume this may be related to the implementation in Gecko and Webkit (not going the whole 9 yards at once, that is; I'm sure it's in the pipelines)

Didn't the error console have any useful error messages?
Intelligent alien life does exist, otherwise they would've contacted us. — CalendarExtend Opera

25. March 2010, 21:49:32 (edited)

triplezero

Posts: 7

No, it took me a while before I realized that when I got "[object Object]" back from the storage, I was looking at the *string* "[object Object]", and not an actual Object sad

Additionally I'm having some trouble using Dragonfly to inspect JS variables so that was no help either (I think I might have broken it with some RC beta "upgrade" or something, I haven't had time to look into it yet).

On the bright side, it does appear that Opera 10.50 has built-in JSON support, so I can use that to serialize my data into strings. Unfortunately I'm having some trouble finding the documentation for the JSON object in Opera, just some examples in articles here and there the API test suite. Anybody got a link to actual API documentation, maybe?

26. March 2010, 07:44:23

Frenzie

Posts: 14438

Originally posted by triplezero:

No, it took me a while before I realized that when I got "[object Object]" back from the storage, I was looking at the *string* "[object Object]", and not an actual Object sad


Ah, I see. sad

Originally posted by triplezero:

Additionally I'm having some trouble using Dragonfly to inspect JS variables so that was no help either (I think I might have broken it with some RC beta "upgrade" or something, I haven't had time to look into it yet).


I would hope it's been fixed by now, but if I inspected the currently stored values during the beta it would invariably cause localStorage to cease functioning until restarting Opera.
Intelligent alien life does exist, otherwise they would've contacted us. — CalendarExtend Opera

26. March 2010, 18:26:15

Opera Software

shwetankdixit

Opera Software

Posts: 49

Originally posted by triplezero:

Why link to the W3 spec if you're not even going to bother to implement it?

I just wasted an hour of my time before figuring out that Opera localStorage is not capable of storing arbitrary values but casts them to strings first!

The specs say that the *keys* are string, but the values can be *any* object to be stored using a special clone algorithm.

Without being able to store structured data like arrays and dicts, this is really not of much use. Anyone know if Opera got a built-in JSON coder? Or do they expect us to go messing about with String.split and Array.join ...



Opera 10.50 has native JSON Support....see this for more info http://my.opera.com/core/blog/2009/12/18/native-json-support-in-opera

However, if you want it to run on other browsers (assuming in case they have support for web storage but not native json support), then it might be better to store data as objects, and use json2.js to convert it to string and then store it (code under public domain available here http://www.json.org/js.html ). When you extract data back from local/session storage, you can similarly use json2.js to re-covert the string back to an object and do whatever you need.

Hope I helped.

9. August 2011, 09:24:02

Lambik

Posts: 16

I cannot believe that now, august 2011, the values are still casted to strings.

9. August 2011, 14:05:03

Opera Software

shwetankdixit

Opera Software

Posts: 49

The spec has been changed to just include strings now. The requirement to support structured clones is gone now in the spec. See http://www.w3.org/Bugs/Public/show_bug.cgi?id=12111#c15 for more details on it.

Even the W3 spec is now updated to reflect this http://dev.w3.org/html5/webstorage/#the-storage-interface

9. August 2011, 20:55:30

Frenzie

Posts: 14438

So basically one would have to use something like this? https://developer.mozilla.org/en/IndexedDB/IDBObjectStore
Intelligent alien life does exist, otherwise they would've contacted us. — CalendarExtend Opera

Forums » Dev.Opera » Archived Article Discussions