0

I am trying to store 1000KB (~1MB) of data in a cookie in JavasSript but it is not working.

How can I do this?

  • A normal string in JavaScript can be more then a megabyte in length; and variables can represent *any* object. However, data-loss (or exceptions) could occur if trying to use such a long string with `setCookie`. Please include more information about what "isn't work". Newer "HTML5" Browsers exposes various "local storage" and web/indexed databases. (Although 1MB might be too big for that as well?) –  Dec 02 '11 at 06:49
  • About max size limit for a javascript string, There is a good answer in http://stackoverflow.com/questions/5926263/javascript-object-max-size-limit – Manjula Dec 02 '11 at 07:00

3 Answers3

2

Don't do that. Sending a megabyte of data takes a lot of time (often more than a second). Keep some session status hidden inside your server. Then your cookie string is just a small opaque identifier which should be keyed by the server.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

For IE, and I'm sure most other browsers, the limit is around 4K

For one domain name, each cookie is limited to 4,096 bytes

http://support.microsoft.com/kb/306070

JeremyWeir
  • 24,118
  • 10
  • 92
  • 107
0

Instead of a cookie use localStorage.

https://developer.mozilla.org/en/DOM/Storage

http://en.wikipedia.org/wiki/Web_Storage

Most browsers allow 5mb per domain, but IE will give you 10mb per domain.

austincheney
  • 1,097
  • 7
  • 8