Cookie
It will be appended to the request header with each request, with a size limit of 4k.
Deployment object: document.cookie
Composition: Key-Value
Validity period: configured according to expires
Optional:
-
;path=path
(eg '/', '/mydir') If not defined, defaults to the path of the current document location.;domain=domain
(eg 'example.com', '.example.com' (including all subdomains), 'subdomain.example.com') If not defined, defaults to the domain name part of the path to the current document location.;max-age=max-age-in-seconds
(e.g. 60*60*24*365 for a year);expires=date-in-GMTString-format
If not defined, the cookie expires at the end of the session;secure
(cookies are only transmitted via https protocol)
API:
-
- docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
- docCookies.getItem(name)
- docCookies.removeItem(name[, path],domain)
- docCookies.hasItem(name)
Local Storage
Size 5M/Domain
Deployment object: window.localStorage
Composition: Key-Value
Storage content format: string
Validity period: permanent storage/manual deletion
Common scenarios: request caching (ajax)
Pros and Cons: Cross-browser sessions; cannot be shared across domains
API:
-
- getItem //Get the record
- setIten//Set record
- removeItem//Remove records
- key//Get the value corresponding to the key
- clear//Clear the record
Session Storage
Validity period: It will be cleared when the page session ends
Note: The page session persists as long as the browser is open, and reloading or resuming the page retains the original page session. Opening a page in a new tab or window initiates a new session.
The rest are the same as Local Storage
IndexedDB
Size: According to different browsers, more than 250M
Transaction-based local data storage
Deployment object: window.indexedDB
Composition: object store storage
Content Format: Near NoSQL database, binary
Advantages: Same domain restriction, use index to quickly locate data, improve search speed
refers:
https://www.cnblogs.com/LuckyWinty/p/5699117.html
http://web.jobbole.com/88241/