01 Oct 2013
Additional means for data storage

Additional means for data storage

Most modern browsers support cookies. For a long time cookies have been the only way to store data making it available after reloading a page. However, the means of storage on a client foresee hundreds of kilobytes and megabytes of data without sending it to the server for each HTTP-query as cookies usually do.   

However, cookies may be still used for session storage, for example.

localStorage is a built-in storage for pairs “name/meaning”. localStorage allows to save information between sessions without reading it by another sites because the access is restricted by a current domen.

General duration of action: data in Local Storage has been saved even after a tab/window/browser close.

Browser support:

IE 8.0+

  • Firefox 3.5+
  • Safari 4.0+
  • Chrome 4.0+
  • Opera 10.5+
  • iPhone 2.0+
  • Android 2.0+

Work with localStorage begins with addressing to the object windows.localStorage()

Data storage:

localStorage.setItem("name", $("#name").val());

Data reading:

var bgcolor = localStorage.getItem("name");

Data deletion:

localStorage.removeItem("name");
localStorage.clear(); // delete all elements

As it was mentioned above, localStorage works only with latest versions of  IE, Firefox, Chrome, Safari, that's why a roundabout decision for older browser versions is needed. There is a way out – data storage on server side or on client side in cookies.

Storage on server side

While downloading the page you check the settings on client side. If they do not exist, you download them from the server. In this case users' settings will be successfully downloaded in any browser. Data sending to the server is provided for this purpose.

Cookie
The object  localStorage that uses cookies in its inner realisation is created.

localStorage=(function()){

    return{
    setItem: function (key, value){
        createCookie(key, value, 3000) // expirationdate3000days.Itis impossible to create cookie withunlimited expiration date, that's why we choose such a long term. 

        getItem: function (key) {
            return(readCookie(key));
} }; })();

SessionStorage

SessionStorage is very similar with localStorage. However, the main differerence is that data stores only when the browser is open and deletes  as soon as the session is over. You need to use the object SessionStorage for work.

sessionStorage.setItem('name', 'John Smith');
var name = sessionStorage.getItem('name');

Database Storage

For work with a big data amount, databases are used. Browsers use  SQLite base which works without additional processes and servers. It works with some restrictions (for example, the absence of external key), but as a result you get a full-fledged SQL database.

Similar posts:


Favourite posts

What it Takes to Get an e-Commerce Site Online

Getting an e-Commerce website online might sound like a huge undertaking,...

WebView Interactions with JavaScript

WebView displays web pages. But we are interested not only in web-content...

Google Maps API for Android

Google Maps is a very famous and helpful service, which firmly entrenched...

Unit Testing with RSpec

RSpec is an integral part of Test Drive Development (TDD) and its main id...

Client side JavaScript: Knockout in practice

When developing a web application that extensively works with user input ...

Accessing Field Configurations in JIRA for changing field description

Field configuration defines behavior of all standart (system) fields and ...

A Guide for Upgrading to Ruby on Rails 4.2.0

As you might have already heard, the latest stuff for upgrading rails was...