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.
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.
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.
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.
- You can split data into more smaller cookies (you can name it in some defined continuous like abcd_0, abcd_1).
- 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.
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.