tags:

views:

110

answers:

3

I want to persist some data between web requests using JavaScript. I would use Google Gears but I can't install Gears on each client machine or expect it to be installed. I found this SO Question but I don't like the idea of storing data in that method. Any suggestions will be welcomed. Thanks!

Edit:

Ideally I want to store "as much data as possible." But 1MB is fine. I'd love for it to work on the major browswer but at least IE/Firefox.

+1  A: 

You would want to use cookies.

http://techpatterns.com/downloads/javascript%5Fcookies.php

cballou
Would you really want to store an significant data in a cookie?
AnthonyWJones
This won't work as cookies don't allow enough data to be stored (I won't downvote as the answer came before the edit that mentioned the limit).
David Dorward
A: 

LocalStorage is a new API in HTMTL5 that is being implemented in modern browsers. It is not available in older browsers though.

Marius
It's unfortunate that IE is strongly lacking in the HTML5 department.
cballou
IE does have an old nonstandard cross page store mechanism so a layer of JS to abstract them might help, however I wonder how many non-IE browsers in common use actually support LocalStorage.
AnthonyWJones
+2  A: 

I would recommend you PersistJS, it's a really small library (3K gzipped) for client-side storage, it uses four persistent data solutions depending on the browser capabilities:

  • globalStorage: Firefox 2.0+, Internet Explorer 8
  • localStorage: development WebKit
  • openDatabase: Safari 3.1+
  • userdata behavior: Internet Explorer 5.5+

The problem with cookies is that they are limited to about 4 kilobytes in size, and they are sent along with every HTTP request.

CMS
I just came across this in more googling. Does this data go away after the session ends(browser closed)? Or do I need to spend some effort cleaning up the data?
Achilles