GUIDELINE 10
Use local browser storage for speed
Cache public, replaceable presentation data locally, then revalidate it against the network before making security or financial decisions.
Reasonable cache data
- Last selected network and cluster, theme, dismissed tips, public addresses, and recently rendered public query results.
- Attach a schema version, network, cluster, public wallet, and expiry to each authoritative-data cache entry.
- Render stale data only when clearly marked, then refresh in the background.
Never persist here
- Passwords, mnemonics, complete keypairs, decrypted messages, bearer tokens, or third-party API secrets.
- Balances, ownership, permissions, transaction success, or contract state as though the cache were authoritative.
localStorage is readable by JavaScript running on the same origin and survives browser restarts. sessionStorage changes lifetime, not its exposure to injected script.
Versioned stale-while-revalidate cache
const key = `wallet:v1:${NETWORK}:${CLUSTER_ID}:${address}`;
const cached = JSON.parse(localStorage.getItem(key) || "null");
if (cached && Date.now() - cached.saved_at < 30_000) {
renderWallet(cached.value, { stale: true });
}
const current = await itza.query_wallet(address);
renderWallet(current, { stale: false });
localStorage.setItem(key, JSON.stringify({
saved_at: Date.now(), value: current // public, replaceable query result only
}));Bottom line
The cache may accelerate rendering; it must never authorize an action or overrule current network state.