Icon Introduction

Modern browsers provide a local data store to browser applications for storing and retrieving strings by a key. This local data store is normally not very large (typically, around 5-10MB). Also, the user can customize the maximum available storage size in the browser, so don't rely on using local storage for storing large amounts of data. However, it can be useful for storing user preferences and interim data that needs to be persisted until the data is saved to a web server application.

Warning Please be very careful about storing sensitive information in local storage. It uses the normal browser cache and is not secure. While this will not be an issue on a private machine/device, the user may not always be using a private machine/device. You should present them with an option to operate without storing such information.

The standard component library surfaces the local storage via the TPersistentStorage component class, and automatically creates two instances of the TPersistentStorage class at application startup:

Storage TypeInstance Variable Name

The SessionStorage and LocalStorage variables are declared in the WebComps unit.

The SessionStorage instance represents only per-session storage, meaning that once the application has been unloaded, any strings stored in this data store will be permanently deleted.

The LocalStorage instance represents browser-wide storage, and persists across instances of the application.

Information The local data store is segmented by origin, which means that each unique protocol, host, and port has its own data store to use. If you loaded your application from http://www.mysite.com/myapp, you would see a different data store than if you loaded your application from https://www.mysite.com/myapp. In contrast, you would see the same data store if you loaded your application from http://www.mysite.com/myapp and http://www.mysite/myotherapp.