Simple Storage is a legacy feature! New apps should use one of the modern alternatives instead:
- Storage Vault for small encrypted values that need to survive uninstall and sync across devices on the same Apple ID or Google account. Backed by iCloud Key Value Store on iOS and Android Key/Value Backup on Android, with optional biometric gating.
- IndexedDB (built into the WebView, no Despia SDK needed) for general-purpose structured local storage with multiple object stores, indexes, and transactions. Works in any browser and inside the Despia runtime.
- PowerSync for a full SQLite database that stays in sync with your backend in real time. Best for apps with non-trivial offline state, multi-device sync, or relational data.
writevalue:// and readvalue:// schemes write and read a single URL-encoded string slot on the device. The data persists between app sessions and is keyed to your app’s bundle, with no sub-keys and no structured access. Pass JSON-stringified data in, parse JSON-stringified data out.
Installation
- Bundle
- CDN
How it works
There is one storage slot per app.writevalue:// overwrites it, readvalue:// returns it. To store anything richer than a single string, JSON-encode an object before writing and JSON-decode it after reading.
encodeURIComponent and decodeURIComponent calls matter. The scheme parser treats &, =, and # as URL syntax, so any of those characters in your JSON will corrupt the stored value without encoding.
Write data
Stringify, encode, write. The whole operation is one round trip with no return value to handle on the write side.Read data
Wait for the read to resolve, then parse. The result object is keyed on whatever key name you passed in the second argument, so['storedValues'] returns { storedValues: '...' }.
try/catch around JSON.parse is worth doing reflexively. Stored data can become corrupt if the URL encoding was skipped on write, or if you change the schema without migrating old values, and a parse error should not crash your app.
Do not block UI on the initial read
The first time a user opens your app, there is nothing stored yet. Treat the empty case as the default state, not as a loading state. Render your UI immediately, then upgrade it once data arrives.Browser fallback
In a regular browser the SDK call is a no-op behind theisDespia guard. Fall back to localStorage for web users so the same save and load functions work everywhere.
Resources
NPM Package
despia-native
Support
Storage Vault
Encrypted, synced, biometric-gated alternative
PowerSync
Full SQLite local database with backend sync