If you want to create mobile applications that perform well, one thing to consider is how to store data on the client side. This is particularly important for mobile applications because they rely on slower connections and might even need to work in offline mode (not connected to a network). Another requirement is that data must be structured and stored in a way that the mobile application can handle.
In any case, having an efficient mechanism for local storage, or caching, can greatly improve the speed and capability of your application. For example, you can use it to:
- Cache data from the web to reduce response times
- Store the state of the application interface (widgets, HTML, settings)
- Store personalization data
- Track user behavior
- And so on
Most web developers are familiar with the concept of caching, and a common method in web application development is to use a cookie. However, cookies have limitations. They only allow up to 4 KB of storage, and they pose an issue for security-conscious people and organizations that turn them off.
There are a number of other options to consider for handling local storage in a mobile application, especially if you need to store more than 4-KB chunks at a time. I will describe a couple of them here.
HTML5 local storage
The HTML5 specification now contains application programming interfaces (APIs) for local storage that are supported in the latest versions of all the major browsers, including WebKit-based browsers like those used by iPhone and Android (version 2.2 or later). This article on developerWorks does a great job of explaining how to use the HTML5 local storage APIs in a mobile app:
IBM Worklight answers this question quite beautifully in version 5.0.5 with the addition of the JSONStore API. This new feature supports offline mode, client-server synchronization and encryption. You can use it to create an application that maintains a local copy of its data (as a JSON data store) and, on request, pushes the local updates to an enterprise system, such as a database.
The JSONStore API is currently supported for hybrid applications that run on Android and iOS devices. If you are targeting these platforms, consider using it instead of the Worklight encrypted offline cache feature (EOC). EOC is a good option for cross-platform development, but it uses HTML5 cache, which is not guaranteed to be supported in future versions of iOS. JSONStore uses the same encryption level as EOC, and it provides more advanced capabilities, as I mentioned here.
In summary, Worklight JSONStore is another great tool to have in your arsenal for creating mobile applications with a better user experience.