2.12 Cookie size

Under 4096 bytes each, and they ride on every request.

Cookie size should be less than 4096 bytes

Cookies are attached to every matching request — each image, stylesheet, script and API call. Unlike page weight, which you pay once, cookie weight is paid repeatedly, and in the upload direction where bandwidth is usually most constrained.

4096 bytes is also the browser's hard limit per cookie. Exceed it and the cookie is silently dropped, which is a correctness bug as much as a performance one.

Keep them small

Store an identifier, not the data. A session ID pointing at server-side state beats serializing a user object into a cookie.

Never put JSON in a cookie. It is bulky, needs URL-encoding — which inflates it further — and the same data belongs in localStorage (never sent) or on the server.

Scope them properly. A cookie set on .example.com goes to every subdomain, including your asset host. Set it on the exact host that needs it, and use Path to narrow further.

Set an expiry. Cookies without one accumulate and never leave.

Do the arithmetic

A page making 60 requests with 3kB of cookies uploads 180kB of headers for nothing.

Check it in the Network panel: look at the request headers on a static asset. If it carries a long Cookie header, that string goes out with every file on the page.

See also cookie count.

On this page