Storing State
Cookies, SessionStorage and LocalStorage
Introduction
The Senza Platform is tailored to offer web developers a familiar environment with standard web UI practices, complemented by specific adjustment for application state management. This page describes the storage options available to your app: sessionStorage, localStorage and cookies.
As part of the Application Lifecycle, your app is unloaded when the UI is released (suspended mode). To let the user pick up where they left off, your app must save its state before it moves to the background and restore it when it is loaded again.
For what to save, when to save it, and how to restore it, see Handling UI Release (Suspend).
Which storage to use
| Storage | Survives UI release (suspend) | Survives disconnect or device reboot | Use for |
|---|---|---|---|
sessionStorage | yes | no (cleared on reboot, not available on disconnect) | State to restore after a UI release |
localStorage | yes | yes | User preferences and settings |
| Cookies | yes | yes (third-party cookies are not persisted across reboots) | Long-lived tokens or flags, data needed after a disconnect |
Session Storage
- Session-level persistence: In the Senza Platform,
sessionStorageretains its standard behavior of persisting data within the same session, similar to a regular browser. The data stored insessionStoragedoes not persist after a device reboot, and it is not available when the session disconnects. - Ideal for managing application state during UI releases: Applications may be released and then restored during a user session.
sessionStorageprovides a reliable means to maintain the application state across these UI releases within the same boot cycle. - Application state restoration: Use
sessionStoragefor the state that needs to be restored quickly when an application is reactivated after a UI release. This gives the user a seamless experience and continuity within the session.
Local Storage
- Standard browser functionality:
localStorageon the Senza Platform functions just as it does in standard web browsers. It stores data per user and persists across browser sessions and device reboots. - Storage capacity: The platform currently supports a storage capacity of about 400KB (after gzip compression). This means about 1MB of storage for
localStoragefrom the developer's perspective, depending on the nature of the text. This capacity is in line with typical web development practices and should accommodate a reasonable amount of user data. - Use cases: Ideal for storing user preferences, settings, and other data that needs to persist beyond a single session and remain accessible across reboots.
Cookies
- Consistent behavior with standard browsers: Cookies in the Senza Platform behave as they do in traditional web environments. They are used for storing user data and are managed based on their specified expiry times.
- Persistence across reboots: Cookies keep their data across device reboots, which makes them suitable for long-term data storage and for tracking user sessions or preferences over time. They are also the right place for data that must remain available after a disconnect.
Note: The Senza Platform does not support persisting third-party cookies across reboots. Chrome, Firefox, and other browsers are starting to block the use of third-party cookies, as described here.
Updated 15 days ago