views:

486

answers:

5

I need to persist my data on the client side, without it moving back and forth in each request (Kills the cookies option). I can't use special plugins/extensions.

One thought I had was to generate a dynamic JS file with the needed data for the current session of the user and make sure it is cached. There is a small problem with that, as in the event this data needs to be changed during the session, it is a bit complex (dirty code).

One more thought: Is there a service (out there in the cloud) which allows me to store key/value pairs and is very fast to access/query with JS? (Someone said Google?)

Is there a better/another way?

+2  A: 

If you really need to do this (and I definitely have doubts that it's a good idea at all), your extra javascript file idea isn't as bad as you think. Just use JSON notation to keep the data and it's pretty easy to load and unload as needed. If you keep in some well-thought-out logical divisions you should be able to update just parts of it on demand, as well.

Joel Coehoorn
+6  A: 

You may store data in window.name, which can hold up to 2MB of data (!).

/* on page 1 */
window.name = "Bla bla bla";

/* on page 2 */
alert(window.name); // alerts "Bla bla bla"

Edit: Also have a look at this Ajaxian article regarding this.

Note that other sites in the same tab/window does also have access to window.name, so you shouldn't store anything confidential here.

moff
There seem to be some security concerns with this method. Have you used it before? Any potential issues you found?
Neil Aitken
Yes, I've used it (mostly for caching though). Other sites in the same tab/window may read or write the window name, so it's not really a safe place to store data in – but for caching and such, I think it's great.
moff
Those other sites could also just overwrite your data, so it's not very reliable either.
Joel Coehoorn
+2  A: 

a google search for persistent client storage gave this http://pablotron.org/software/persist-js/

Vardhan Varma
A: 

What about Amazon SimpleDB?

Rich
+2  A: 

What about Google Gears. It is made for offline storage, but I think it might work. http://code.google.com/apis/gears/design.html

From the documentation:

Storing User's Data

Applications that are more than just static files have data that is typically stored on the server. For the application to be useful offline, this data must be accessible locally. The Database module provides a relational database for storing data. On the Architecture page you will find a discussion of strategies for designing the local storage that your application needs.

When an offline application reconnects, you will need to synchronize any changes made in the local database with the server. There are many different approaches to synchronizing data, and there is no single perfect approach. The Architecture page describes some strategies for synching.

An additional feature of the Gears database is Full-Text Search, providing a fast way to search text within a database file. Read the details here.

Martin
Requires an extra component installed in the browser, which breaks one of his requirements.
Joel Coehoorn