This topic has been closed. No new entries allowed.
Reason: You can now post comments on articles on Dev Opera
You need to be logged in to post in the forums. If you do not have an account, please sign up first.
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 )
Originally posted by tomassplatch:
I think this is only part of what Gears did. Do you know anything about the data limits of Gears?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?
It also allows easier storage of data than cookies, and in much greater amount too.
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"
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 ...
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?
25. March 2010, 21:49:32 (edited)

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
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
Ah, I see.

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.
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.
Even the W3 spec is now updated to reflect this http://dev.w3.org/html5/webstorage/#the-storage-interface