Handle Cache with Jquery

Asked

Viewed 487 times

0

Hello

I need to work with the cache of all browsers, I need to store data in the cache and then read using Jquery. Does anyone know any site with tutorial on the subject ?

Thank you

1 answer

0


Using the localStorage

The localStorage saves data on the visitor’s computer, which are linked to (and only accessible by) their domain. And to use is very simple:

// Cria um item "usuario" com valor "Usuário 1"
window.localStorage.setItem('usuario', 'Usuário 1');

// Depois, em outra página ou aba, recupera esse item
var usuario = window.localStorage.getItem('usuario');

// Remove o item
window.localStorage.removeItem('usuario');

Using the sessionStorage

Already the sessionStorage does exactly the same thing, only the data is saved only during the session (and is deleted when the visitor closes the tab/browser):

// Cria um item "usuario" com valor "Usuário 1"
window.sessionStorage.setItem('usuario', 'Usuário 1');

// Depois, em outra página ou aba, recupera esse item
var usuario = window.sessionStorage.getItem('usuario');

// Remove o item
window.sessionStorage.removeItem('usuario');
  • Amazing, thank you friend.

Browser other questions tagged

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