javascriptcookiesjs-cookie

How to store a long string in Js Cookies?


Hi I am working with JsCookies it is working good but I am facing a problem

Whenever I store a short string in the cookies, it is working fine but the drawback is i am not able to store long strings in cookies

for example

This is working fine = Cookies.set('Coo', 'string', { expires: 1 })

But facing problem when ever i am trying to store stringified JSON data(large string)

Cookies.set('foo', JSON.stringify(result))

Please help


Solution

  • Cookies should not be used to store large amounts of data. They should be used for stuff like user authorization and configuration options (which, all together, don't add up to much of a payload). Use cookies when the data is relevant to both the client on the server on every request.

    Large payloads in cookies should not be sent with every request; it'd be bandwidth-intensive and unnecessary. Instead, either: