basic concept
cookie
English biscuit cookie, by definition, the size should be very small, very small cookie, its size is limited to about 4kb, is a former employee of Netscape's invention in 1993. It is mainly used to save login information, such as your landing site market may see a 'remember password', which is distinguished by storing data for a user's identity in a cookie to achieve.
localStorage
HTML5 localStorage is newly added standard technology, of course, as early as the age of IE6 userData have a thing for local storage, while taking into account the time browser compatibility, more general solution is to use flash. Today localStorage is supported by most browsers.
sessionStorage
Similar sessionStorage and localStorage interface, but save the data life cycle with different localStorage, did the back-end students know Session of the word, which translates to the session. And sessionStorage is a concept front end. It may just be part of the data saved in the current session, refresh the page data is still there. However, the closed YeMin ah, sessionStorage the data will be cleared.
Similarities and differences of the three
Different life cycle of the data
Cookie typically generated by the server, expiration time may be provided, if the browser generates a Cookie, the default is off failure.
localStorage unless permanently erased, or stored permanently.
sessionStorage clear only in the current session will be effective after the close the page or browser
Storage of data of different sizes
Cookie generally 4kb
localStorage and sessionStorage generally 5mb
Communicate with different server
Cookie each will carry the HTTP header, if you use a cookie to save too much data can cause performance problems
localStorage and sessionStorage only stored in the client (ie browser), and not involved in the communication server.
Ease of use
Cookie require the programmer to encapsulate, a native of the interface is not friendly enough cookie
sessionStorage localStorage and native interfaces acceptable, may be packaged to have a better support for Object and Array.
Scenarios
Considering that each HTTP request will take information of Cookie, Cookie, of course it can be streamlined to streamline the force, a more common scenario is to determine whether the user is logged in, go to the Cookie when it landed against the landing of the end user services blessing in some encrypted uniquely identify a single user identification code, as long as the next read this value you can determine whether the current user login. Cookie has been used to store information on a user's shopping cart site electricity supplier, has now come localStorage, all these issues become more and more relaxed.