HTML5 APPLICATIONS DEVELOPMENT MANUAL

(lu) #1

5 - Application State


A session state is created when a user first requests access to an


application, and it ends when the session closes, such as when a user logs off.


An application state exists from the time a Web browser requests a


Web page until the browser closes. Persistent state information is data that


exists after a session ends. In HTML5, developers can use the localStorage


and sessionStorage JavaScript methods to deal efficiently with state data. In


addition, AppCache enables a user to load data ordinarily stored on a server


even when the user is offline.


Storing State Data Using Local and Session Storage


When we enter a uniform resource locator (URL) into the address


bar of a browser, the browser sends an HTTP request to a Web server for a


Web page.


HTTP is short for Hypertext Transport Protocol. HTTP is a


stateless protocol, which means that it doesn’t retain data from session to


session.


Therefore, when we close a Web browser after using an application,


data is not automatically saved.


To work around the limitations of HTTP protocol, developers


historically have used cookies, which are small files that contain information


about the user and the Web site visited and are saved on the user’s computer.


When a user returns to a visited site, the browser sends the cookies back to


the Web server. Cookies help a Web server “remember” a user and customize


the user’s experience on that site.


However, cookies have proven to be a security risk. In addition, if


large amounts of data are involved, all the data gets sent between the browser


and server upon every request, which would cause a noticeable performance


decrease to the user.

Free download pdf