MutterCorp
MutterCorpNotice · Notícias
Programação·

A scoreboard that survives refresh, and three real localStorage traps

The scoreboard is pure client state, but users refresh by accident, and mobile OSes kill background tabs. Without persistence, a 7:5 game vanishes on refresh. My first instinct was "one line of localStorage, done." Then I found three traps: Trap 1: Safari private mode localStorage.setItem throws QuotaExceededError in private mode. Not because the quota is full — because the mode disables storage entirely. You must try/catch: function save(state) { try { localStorage.setItem('swg:score', JSON.st…

Publicado no Notice. Categoria: Programação.

Mais recentes em Programação