Chris Simpson
Chris Simpson

Reputation: 8000

Should I spread my data across multiple cookies to work around the 4k limit

I have it so that users can copy and paste objects from one page to another. I use cookies to hold the object data.

On very rare occasions the amount of data (when escaped) has exceeded the 4k limit.

There are two ways around this I can see.

  1. compress what goes into the cookie (in tests this will give me about 5 times the capacity)
  2. test the data and if it exceeds 4k, spread it across multiple cookies (building in some chaining mechanism so they can easily be reconstructed)

I think the first solution might just push the problem further under the carpet and will come back and bite me in months to come.

But is the second solution a good idea? Has anyone done it before or is there some other client side storage mechanism that would be better here?

NB: I have used sessvars.js elsewhere in the site and I have been looking at using jstorage

Upvotes: 3

Views: 318

Answers (3)

Josiah Ruddell
Josiah Ruddell

Reputation: 29831

HTML5 localStorage is very useful. I do not know your requirements but it is compatible in IE8+, and most modern browsers.

Upvotes: 2

Chris Simpson
Chris Simpson

Reputation: 8000

I've decided to go ahead and use jstorage as mentioned in the question. It's a decent alternative to what I have and makes use of html 5 localstorage if the browser allows it.

Upvotes: 1

fcalderan
fcalderan

Reputation:

Have you already considered to use localstorage instead? You have 4/5 Mb of space depending of which browser you are using

http://net.tutsplus.com/tutorials/html-css-techniques/quick-tip-learning-about-html5-local-storage/

Anyway on older browser not supporting localstorage I would choose the first solution because cookies are passed with http headers so I'd prefer less cookies solution.

Upvotes: 2

Related Questions