Automatic signal persistence with localStorage and sessionStorage
Values automatically saved to localStorage and restored on page load:
Try typing, then refresh the page!
Counter persists across page reloads, but reset clears both display and storage:
This data is only saved for this browser tab and cleared when the tab closes:
🔄 Refresh this tab: data persists
🆕 Open in new tab: data doesn't persist
Choose which signals to persist and which to keep temporary:
Reload the page: score persists, lives reset to 3
Toggle between light and dark themes - your preference is remembered:
Your theme choice persists across page reloads!
Demonstrating different persistence patterns:
This counter will reset on every page reload (persistence disabled).
These values use a custom storage key: 'starhtml-persist-myapp'
Only tabId persists in this tab session. Page views reset every reload.
Tools to manage and debug your persisted data:
⚠️ These actions will only clear StarHTML persist data from this demo
The persist handler is a simple yet powerful Datastar attribute plugin:
data_persist="signal_name"
- Persist a specific signal data_persist="signal1,signal2"
- Persist multiple signals data_persist=signal.with_(session=True)
- Use sessionStorage data_persist=([signal1], dict(key="mykey"))
- Custom storage key starhtml-persist