Difference cookies, sessionStorage and localStorage of (the difference between the browser cache)

. 1, Cookie
(. 1) itself for client and server communications
(2) it has the function of local storage, so they are "borrowed"
(. 3) to retrieve and modify the document.cookie = ... to
(4) cookie with to the disadvantage of storage
① storage capacity is too small, only 4KB
② with all http requests, it will affect access to resources efficiency
③api simple, needs to be encapsulated in order to use document.cookie
2, localStorage, sesseionStorage
(1) html5 designed specifically for storage The maximum capacity of 5M
(2) API is easy to use
(3) lcoalStorage.setItem (Key, value); localStorage.getItem (Key);
(4) under ios safari hidden mode: localStorage.getItem will complain, it is recommended to use a unified try- catch package
3, sessionStorage a local storage for data session (session) of these pages can only access data in the same session and after the session ends data also will be destroyed. So sessionStorage not a persistent local storage, only the session-level storage. The localStorage for persistent local storage, unless the initiative to delete data, or the data is never out of date.

Guess you like

Origin www.cnblogs.com/gitwusong/p/11368489.html