The users of a typical online web application are not able to use the application without internet connection. In offline mode they cannot access data such as inbox of mail, calender appointments etc. But in a desktop application everything is stored locally as some data files.
Now we have a solution for this . HTML 5 is much more than a typical markup language. HTML 5 provides some solutions for this problem. The two major features of HTML 5 for data storage are :
- SQL-based database API.
- Offline Application HTTP Cache.
SQL-based database API
This API helps in structured data storage using a client-side SQL database. The window object has the openDatabase() method to create database objects. The arguments for this method are:
- Database name
- Database version
- Display name
- Estimated size in bytes
The transaction() method is used to have further transactions with the created database. The arguments of this method are:
- Transaction callback
- Error callback
- Success callback
- SQL statement
- SQL statement callback
- SQL statement error callback
Offline Application Caching API
The manifest attribute of <html> element helps to make the web applications available even when the internet is not connected. The manifest attribute takes an URI to be cached. It stores some information in a file like this :
The server.cgi should never be cached so that any attempt to access that file will bypass the cache. All other files specified get cached.
The manifest is linked by declaring like this
The server.cgi is in Network: section so that it can be accessed to get updated from the server as in
HTML 5 introduced the new element <event-source> to continuously stream updates from server to a webpage.
HTML 5 contains some other APIs also which helps in data storage. For example onLine attribute of Navigator object determine whether the user is currently online.
localStorage attribute of Window object also helps in simple synchronous storage access.
The offline storage is helpful for mobile web applications to work offline. The user can work offline with the local database and can share the data with the server database when going online