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+
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.
Kategorien
Schlagworte
Favoriteneinträge
Getting an e-Commerce website online might sound like a huge undertaking,...
WebView displays web pages. But we are interested not only in web-content...
Google Maps is a very famous and helpful service, which firmly entrenched...
RSpec is an integral part of Test Drive Development (TDD) and its main id...
When developing a web application that extensively works with user input ...
Field configuration defines behavior of all standart (system) fields and ...
As you might have already heard, the latest stuff for upgrading rails was...