localStorage
Definition
localStorage is a browser key and value store scoped to one origin, holding strings with no expiry until something clears them. It is never sent to the server, so nothing in it can change a rendered page or a cart by itself. Themes use it for state that should survive navigation but doesn't belong on the order record.
Documented at MDN, localStorage.
How We've Used It
We use it for shopper-side state the cart shouldn't carry. A comparison drawer is the clearest case: the chosen products are serialized under one key by a debounced writer, so a selection survives moving between a collection and a product page, while the heavy part, the comparison copy itself, is fetched once per product and cached rather than rendered into every card in a grid. The rules we hold to are that it stores keys and not content, that every read is wrapped because storage can be full or unavailable, and that nothing a shopper is about to pay for lives there. That belongs in the cart.
Builds Using It
Related Entities
- Custom elements — the components that read and write it.
- Cart AJAX API — where a real selection has to end up.
- History API — state that belongs in the URL instead.