Can you save / retrieve cached information using javascript / jquery?

0

Motivation, having an offline application, is it possible to save cached information and be sent as soon as the user accesses the page again?

How long would this cache last if possible? and what are the limitations?

Ps. is using the html5 manifest

    
asked by anonymous 14.06.2017 / 16:28

1 answer

4

With html5 you can use localstorage = local storage.

Explanation:

  

What is local storage in HTML?   With local storage, web applications can store data locally in the user's browser.

     

Before HTML5, application data should be stored in cookies, included with every request from the server. Local storage is more secure and large amounts of data can be stored locally, without affecting site performance.

     

Unlike cookies, the storage limit is much higher (at least 5MB), and information is never transferred to the server.

     

Local storage is by source (per domain and protocol). All pages from a source can store and access the same data.

Using locaStorage:

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = 
localStorage.getItem("lastname");

Check your browser for support:

if (typeof(Storage) !== "undefined") {
// Código localStorage/sessionStorage.
} else {
// Desculpe! web storage não suportado.
}
    
14.06.2017 / 16:46