0

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.

Community
  • 1
  • 1
Achilles
  • 11,165
  • 9
  • 62
  • 113
  • How much data do you want to store? – moff Oct 14 '09 at 14:34
  • any cross browser requirement? – Rubens Farias Oct 14 '09 at 14:36
  • 1
    Any mitigating scenarios specific to this question which makes it unique from the question you linked? Otherwise the answer is: See the answers to that question. What exactly don't you like about those answers? – AnthonyWJones Oct 14 '09 at 14:38
  • @AnthonyWJones it just seems to be a "clueg." There has to be some supported way that doesn't require a hack like that. – Achilles Oct 14 '09 at 14:43
  • 1
    @Achiles "I want to do X" has never been a reason for X to be possible, especially on the WWW. :) – Quentin Oct 14 '09 at 15:01
  • @David Dorward that's a good point. I might be trying something that isn't possible which means I can go back and rethink some design elements, but I'd love to make sure before I scrap this idea. – Achilles Oct 14 '09 at 15:03

3 Answers3

3

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.

Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
  • 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 Oct 14 '09 at 15:01
1

You would want to use cookies.

http://techpatterns.com/downloads/javascript_cookies.php

Corey Ballou
  • 42,389
  • 8
  • 62
  • 75
1

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

Marius
  • 57,995
  • 32
  • 132
  • 151
  • 1
    It's unfortunate that IE is strongly lacking in the HTML5 department. – Corey Ballou Oct 14 '09 at 14:38
  • 1
    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 Oct 14 '09 at 14:42