Preserving 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 documentation highlights these features, emphasizing the use of sessionStorage for application state management and the standard functionality of localStorage and cookies.

As part of the Application Lifecycle, your app may be unloaded after a period of time while in the background. For the user to pick up where they left off when returning to the foreground, your app should preserve its state as follows:

  1. Before switching to the background, save the current state.
  2. After switching to the foreground, restore the state if the app has been restarted.

Session Storage

  • Session-Level Persistence: In the Senza Platform, sessionStorage retains its standard behavior of persisting data within the same session, similar to a regular browser. This means that the data stored in sessionStorage will not persist after a device reboot.

  • Ideal for Managing Application State During UI Releases: Given the nature of the Senza Platform, where applications may be released and then restored during a user session, sessionStorage becomes particularly useful. It provides a reliable means to maintain the application state across these UI releases within the same boot cycle.

  • Application State Restoration: Developers should utilize sessionStorage for storing the state that needs to be quickly and effectively restored when an application is reactivated after a UI release. This ensures a seamless user experience, maintaining continuity within the session.

Local Storage

  • Standard Browser Functionality: localStorage on the Senza Platform functions just as it does in standard web browsers. It provides a method for storing data per user, allowing for data persistence across browser sessions and device reboots.
  • Storage Capacity: The platform currently supports a storage capacity about 400KB (after performing gzip compression) this mean about 1MB of storage for localStorage from developer 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 need 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 maintain their data across device reboots, making them suitable for long-term data storage and tracking user sessions or preferences over time.