views:

64

answers:

5

I have been writing a php script that saves a long string within cookie (more than 4000 chars long) and I want to save it within the browser cache. The problem is that almost all browsers have a limit. What should I do? I'm using jQuery for adding and reading data from cookie and php.

A: 

I know your looking for a JQuery solution, but perhaps this will give you a starting point to look for a JQuery option. Its html 5 data storage on the client side. 10 megs in IE, and 5 megs in all other browsers. I believe yahoo has a solution in theirs for non-HTML 5 browsers.

http://developer.yahoo.com/yui/storage/

Zoidberg
A: 

Rethink your App logic and save most of the data on server.

This will save you a lot of hassle in the long run.

Just my two cents.

Frankie
+1  A: 

Check out Web Storage Portability Layer: A Common API for Web Storage

It abstracts the various local storage mechanisms that browsers provide.

Local storage is becoming standardized in HTML5.

Paul Annesley
can you please give a quick example for the lazy? :)
JohnRoach
@Paul Annesley even though it's not probably what John's looking for, as IE is way behind it's a nice one. +1!
Frankie
@JohnRoach stackoverflow is not a site for the lazy...
Frankie
@Frankie actually it is what I'm looking for :D Though I need an example on how to do that... And I need to know the limits.(which I'm reading on right now) @Paul Annesley an example please
JohnRoach
Actually I may have been thinking of a different abstraction library. Either way - find one that abstracts across the various browsers you want to support. If you only need to support modern HTML5-capable browsers, then life is good, just check out the HTML5 Web Storage docs.
Paul Annesley
This is more like what I was thinking of: http://github.com/marcuswestin/store.js
Paul Annesley
@Paul also a very nice one this on github!
Frankie
Ok found answer. The answer is using "localStorage". A good example can be found at http://html5demos.com/storage
JohnRoach
A: 
  1. You can split data into more smaller cookies (you can name it in some defined continuous like abcd_0, abcd_1).
  2. You can save string at server side (in database or server filesystem) and save in cookie only MD5 checksum of this string, and when you want read this string you must transport cookie value (MD5 checksum) at server side and do query in the database or search in filesystem to obitan data and transport to browser.
Svisstack
A: 

You can use jQuery data method to store data:

http://api.jquery.com/jQuery.data/

jQuery itself uses this method to store information.

But this will not persist the data.

Why not store the information in a hidden field in the form? But that again is going to remain stored only until the browser is not closed.

ovais.tariq
@ovais.tariq this stores data in the DOM. Is lost after page refresh and browser navigation. How can it help him?
Frankie
Thank you Frankie for pointing it that out. Sorry ovais.tariq no cigar.
JohnRoach
lol yeah you are write., i may be didnt read the question properly, this data is not going to get cached. my bad., i have edited my answer
ovais.tariq