About localStorage and sessionStorage

First, what is Storage

  Storage of data is stored to a local web Brower a way that data in the form of key-value pairs stored in the web storage on the local server. Storage is divided into sessionStorage and localStorage.

  sessionStorage: temporarily storing, for each storage region to maintain a data source, the process of opening and loading the page exists in the browser.

  localStorage: long-term storage, for each data source to maintain a storage area, long-term presence in the browser, unless manually removed.

  sessionStorage valid session time is the browser when the browser is closed, sessionStorage automatically cleared, the scope including windows, protocol, host, port. localStorage The validity is permanent, including the scope of the protocol, host, port. Storage size are 5M.

Two, storage use

 For the browser to store data, stores some very common but not very important or not very private data. Can reduce http requests, optimize results.

Third, how to use

  Storage There are web Storage Api give us a call. Use sessionStorage and localStorage is the same. Note: The reference types are converted to their values ​​in Json.

  1, save data

There are two sets of data as follows:

 

 

 

  2, get

 

   3, delete

 

   4, monitor

 

 5, the browser how to view

 

 

 

Guess you like

Origin www.cnblogs.com/mahmud/p/11767099.html