Skip to main content

Browser Storage

There are many ways to store data on the browser: cookie, localStorage, sessionStorage, indexedDB, etc.

Our core module provides you with the classes/functions for handling this need. We encourage you to use these functions rather than, say, calling localStorage directly.

Key definition

The first thing you should note is that you should store your key and documentation inside the @traveloka/app-meta package. This allows us to keep track of what local data keep for documentation and auditing purposes.

// Instead of this
localStorage.setItem('myKey', 'myValue');

// Do this
import { LocalStorage } from '@traveloka/core';
import { lsPlaMyKey } from '@traveloka/app-meta';
LocalStorage.get(lsPlaMyKey);

The different flavors

See packages/core/storage

  • SessionStorage — Wrapper for the browser's sessionStorage
  • LocalStorage — Wrapper for the browser's localStorage (recommeded for most use cases)
  • ExpirableLocalStorage — Works like LocalStorage, but you can set the TTL (we perform cleanup periodically)
  • Cookie — wrapper for cookie (use this sparingly, i.e. only when both the server and the client need to read this data)
  • ExpirableIDBStoreIndexedDB with TTL, currently used very rarely. (There's also an implementation overlook that makes you can only have one "store" inside one "db".)