cookie、localStorage、sessionStorage

Cookie drawbacks

  1. The number of generated cookie
  • In IE6 or less, a maximum of 20 cookie
  • IE7 future releases up to 50 cookie
  • Firefox cookie Up 50
  • Chrome and Safari is no hard limit
  • IE and Opera will clean cookie no recent use, Firefox random cleanup
  • cookie up to 4096 bytes, for compatibility is generally not more than 4095 bytes
  • IE5 above provides userData, store up to 1M Under each domain name. Stored in the cache, if not cleaned, long time.
  • The cookie advantages: persistence data; the client, the server does not occupy storage resource cookie; cookie may be provided an effective period; simplicity, d text-based lightweight structure.
  1. The rational use of the advantages of the cookie
  • Through good it becomes possible to control the session object stored in a cookie the size of the
  • Through encryption and secure transmission technology, reducing the likelihood of cookie being cracked.
  • Not only to store sensitive information in a cookie theft will not cause significant losses.
  • Control is valid
  1. cookie shortcomings
  • cookie number and size is very limited
  • Security issues. You do not need to crack and forwards to achieve their goals.
  • Range is limited. Not all states can be resolved by saving the cookie.

The storage html

  1. html5 provides two storage methods: sessionStorage and localStorage. Both collectively webstorage, different browsers can not be shared, shared localStorage same browser. Homologous to meet the case can be shared sessionStorage. Both are stored on the local client. Type is a string type is stored
  • About the size of 5M (different in different browsers)
  • sessionStrorage: local storage of a session is valid data, only the session-level data, the data will be destroyed after the end of the session.
  • localStorage is a long-term effective local storage, non-active deleted, has been effective.
  1. method of obtaining
  • sessionStrorage:window.sessionStrorage
  • localStorage:window.localStorage
  1. Scenarios
  • Long-term effective use localStorage
  • Effective use of a sensitive operation sessionStrorage
  1. Compared cookie
  • It can store more data.
  • Save traffic, save server resources: Because not transferred to the server, saving flow. And obtain faster than the local server, so more efficient.
Released two original articles · won praise 0 · Views 19

Guess you like

Origin blog.csdn.net/qq_40944052/article/details/104532441