The difference between sessionstorage, localstorage, and cookies

Source: Internet
Author: User
Tags send cookies sessions sessionstorage
Sessionstorage and Localstorage (also known as Dom Storage) are provided by the HTML5 WebStorage API to easily save data between Web requests. With local data, you can prevent data from being passed back and forth unnecessarily between browsers and servers. In common: All are stored in the browser-side, and homologous. Difference: Cookie data is always carried in a homologous HTTP request (even if it is not needed), that is, the cookie is passed back and forth between the browser and the server. Sessionstorage and Localstorage do not automatically send the data to the server, which is saved locally. CookiesDomain +path+name Identity Name+value, there is a server generated, sent back to the client, saved in the client (HTTP set-cookies field) every HTTP request will send cookies in the "domain +path" the same all Cookies Most browser cookies Max 4K browsers may also limit the number of cookies stored on the user's computer (such as allowing each site to store up to 20 cookies, exceeding the old ones; some browsers also limit the total number of cookies in all sites, such as 300) Local StorageDomain related permanently stored in local (client) capacity unrestricted data will not expire unless the user requests to delete for security reasons Session StorageSimilar to local Storage, but session Storage is only relevant to current sessions, and browser shutdown is deleted. The special place is: Top Browser the context, and all frame/iframe in the same page share the same session storage; Different page has different sessions storage conversation ends Delete INDEXEDDBCompared to the local Storage (DOM Storage), INDEXEDDB is used for a large number of structured data stores for the client, and the local Storage belongs to small data storage. Features include:

One domain A database Key-value method is built on the relational data model, and the concepts of index table, cursor, transaction meet some offline Web applications requirements to emphasize that indexeddb belong to large amount of data storage, and local Sto Rage belong to small amount of data storage. Its implementation in WebKit is as follows: All data is read into memory when the local Storage is initialized, followed by operation for memory operation, but there is a background synchronization thread that writes the data to the Sqlite3 database; So the local Storage API is a synchronous operation 。   But for INDEXEDDB, the data volume is large, obviously can not all read into the memory, using the annotated database read and write mode, in the window is used asynchronous operation mode, only in the worker environment is synchronized. Recommendation: http://blog.csdn.net/shuimuniao/article/details/8027276

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.