How to Store Data for Offline Access Using Local Storage, IndexedDB, or a Device's File System

Description

Data can be stored offline in several locations depending on the application type.

Discussion

Web and mobile applications can store data offline, making it available when a network connection is not available. There are several locations where data can be stored. This includes Local Storage, IndexedDB, or the device's File System (Cordova apps only). Alpha Anywhere includes integrated offline support for all three storage locations in the List control. JavaScript methods also exist to save and load data directly from client-side storage. The pros and cons of each are outlined below.

Storing data in Local Storage 

Benefits: Simple. Widely supported across most browsers.

Drawbacks: Users can view and modify data in Local Storage using tools within the browser. Limited storage space -- 5MB. Can only store string data. Persistance is not guaranteed and there are many conditions where browsers will delete your data from Local Storage. Supported by a variety of controls and features, including the List control, Client-side Data Cache, and the UX (persisting variable values).

Client-side Methods:

Storing data in IndexedDB 

Benefits: Can store any type of data. Significantly more storage space -- IndexedDB offers a minimum of 1GB of storage in most browsers. More predictable than Local Storage. Saving data is transactioned and asynchronous, meaning IndexedDB operations will always complete and saving/loading data does not block JavaScript execution. See IndexedDB Methods for more details.

Drawbacks: Not all browsers support IndexedDB -- yet. Verify your target environment supports IndexedDB before using it. Users can view and modify data in IndexedDB using tools within the browser. Only the List Control and Client-side Data Cache have integrated support for storing data in IndexedDB. For everything else, you will need to use the IndexedDB Methods.

Client-side Methods:

Storing data in a Device's File System 

Benefits: Can use Action Javascript to write your data to file. No storage limitations other than the size of the device's hard drive.

Drawbacks: Limited to Cordova Applications installed on the device or distributed using Alpha Launch. Cannot be used in web apps.

Methods: