Can you cache/retrieve information using javascript/jquery?

Asked

Viewed 2,894 times

1

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

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

Ps. is using the Html5 manifest

1 answer

6

With Html5 you can use localstorage = local storage.

Explanation :

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

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

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

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


Using the rental site:

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

Check for browser support :

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.