11.07.2015 Views

Client-Side Storage in Web Applications

Client-Side Storage in Web Applications

Client-Side Storage in Web Applications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

common objective shared by all the APIs is to, one way or another, overcome thelimitations of legacy client-side storage mechanisms. In the follow<strong>in</strong>g subsections,these three HTML5 client-side storage mechanisms are presented along with a briefsecurity analysis and feature comparison.3.1 <strong>Web</strong> <strong>Storage</strong><strong>Web</strong> <strong>Storage</strong> 4 [11], a W3C Candidate Recommendation s<strong>in</strong>ce December 2011, isthe oldest and simplest of the three client-side storage APIs. It is a direct replacementto HTTP cookies and offers more advanced capabilities for stor<strong>in</strong>g small-sized data(e.g., session <strong>in</strong>formation or user preferences) on the client side through the use ofJavaScript.The API specification def<strong>in</strong>es two mechanisms for stor<strong>in</strong>g and manag<strong>in</strong>g simplekey-value pair data. The first mechanism is designed for stor<strong>in</strong>g session-related(short-lived) data, i.e., the data disappears once the current session is term<strong>in</strong>ated, suchas when a web browser or its tab is closed. The second mechanism is designed forstor<strong>in</strong>g persistent (long-lived) data, i.e., the data rema<strong>in</strong>s available beyond the currentsession and is even available across multiple web browser tabs. For both mechanisms,the same API is used. The only difference is that the data is accessed through the session<strong>Storage</strong>and local<strong>Storage</strong> objects, respectively.List<strong>in</strong>g 1 shows a simple example of the API usage. In l<strong>in</strong>es 1-5, data is def<strong>in</strong>ed <strong>in</strong>the JSON format. L<strong>in</strong>es 7-9 demonstrate how to serialize the JSON data as str<strong>in</strong>g andstore it persistently with the given key <strong>in</strong>to a local storage. F<strong>in</strong>ally, the data is retrievedfrom the storage and converted back to JSON (cf. l<strong>in</strong>es 11-13). In addition tostor<strong>in</strong>g and retriev<strong>in</strong>g data, the API provides means for remov<strong>in</strong>g and clear<strong>in</strong>g datafrom the storage as well as for listen<strong>in</strong>g to storage events fired when changes occur <strong>in</strong>the storage.1: // Def<strong>in</strong>e data2: var myData = {3: "code": "T-111.5502",4: "name": "Sem<strong>in</strong>ar on Media Technology B P"5: };6: ...7: // Store data8: local<strong>Storage</strong>.setItem( "1",9: JSON.str<strong>in</strong>gify( myData, null, "\t" ) );10: ...11: // Retrieve data12: var myResult =13: JSON.parse( local<strong>Storage</strong>.getItem( "1" ) );List<strong>in</strong>g 1. The <strong>Web</strong> <strong>Storage</strong> syntax example for stor<strong>in</strong>g and retriev<strong>in</strong>g data.4 Also referred to as DOM <strong>Storage</strong>, HTML5 <strong>Storage</strong>, Local <strong>Storage</strong>, and Offl<strong>in</strong>e <strong>Storage</strong>.5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!