DEV Community

Jeeho Lee
Jeeho Lee

Posted on

1

Limitations of Cookies

When I was working on my PokeLucky application (https://github.com/jeeheezy/sinatra-pokelucky), which interacts with the PokeApi, I tried to respect the PokeApi rule to cache information so there wouldn't be too many repetitive API calls. Since I was unfamiliar with how to cache information, I decided I'd just store the necessary data I got from the API into cookies to call back a later time. All was working fine until at a certain point, I got an error saying that I was trying to parse a nil object. Taking some time to debug, I found out it was because my conditions which look at if a Pokemon info was saved on a cookie did not take the expected "if" condition.

The core of the issue was that at a certain point, my cookie did not update with the latest information from the API because it had gotten too big. It seems that cookies have a byte limit of ~4000 bytes, which is not a lot. Even more to consider is that the best practice is to ensure the total bytesize of cookies doesn't exceed ~4000 per domain, not per cookie. I guess this is why learning how to use sessionStorage or localStorage is important since their storage capabilities are far greater than that of 4kb of cookies, although I'm not sure how one would access them in Ruby since I understand the two storages to be more front-end related.

TL;DR, cookies have bytesize limit and should not be the primary location to save continuous influx of data.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more