Web Data Storage Summary

Source: Internet
Author: User
Tags browser cache ssl connection

With the advent of Web applications, there are also requirements for the ability to store user information on the client. The first solution to this problem is a cookie-shaped appearance. Netscape describes the cookie mechanism in a standard named "Persistent Client state:http cookies". Cookie Restrictions:
    1. The number of cookies per domain is limited, after IE7 is 30 per domain, Firefox is 50, Chrome and Safari have no restrictions
    2. When the cookie limit for a single domain is exceeded, the browser will be cleared before the Cookie;ie and opera will remove the least recently used Cookie;firefox deletion and there is no regularity
    3. There is also a limit to the capacity of a single cookie, which will disappear silently at up to 4kb, exceeding 4kb per cookie.
The composition of the cookie:
    • Name: A unique name that determines the cookie. The name of the cookie must be a URL-encoded
    • Value: The string value stored in the cookie. Value must be URL encoded
    • Domain: A cookie is valid for which domain. All requests sent to this domain will contain this cookie information. This value can contain subdomains: Www.wrox.com can also not include subdomains:. wrox.com
    • Path: Specifies that a cookie should be sent to the server for that path in the domain.
    • Expiry time: timestamp indicating when the cookie should be deleted. By default, all cookies are deleted at the end of the browser session, and if the expiration time is set, the cookie remains on the user's machine after the browser is closed.
    • Security flag: Once specified, the cookie can only be sent to the server when the SSL connection is used.
Note In particular: the domain, path, expiration time, and secure flag are all instructions that the server gives to the browser to specify when the cookie should be sent. These parameters are not used as part of the cookie information sent to the server, only the name value pairs will be sent. The Document.cookie browser provides access to and settings for cookies. What is special about this property is that it behaves differently because it is used in a different way:
    • When used to obtain a property, Document.cookie returns the string of all cookies available on the current page (based on domain, path, expiration time, and security settings), a series of key-value pairs separated by semicolons: "nam1=value1;name2=value2;name3= Value3 "Note that there is no semicolon at last
    • When used to set a value, the Document.cookie property can be set to a new cookie string. This cookie string is interpreted and added to the existing collection of cookies. Setting Document.cookie does not overwrite cookies unless the cookie name already exists. : document.cookie=encodeuricomponent (name) + "=" + encodeuricomponent (value) + "; domain=.wrox.com; path=/";
The purpose of webstoragewebstorage is to overcome some of the limitations imposed by cookies, which do not need to be continuously sent back to the server when data needs to be tightly controlled on the client. Two main purposes of WEB storage:
    • Provides a way to store session data outside of a cookie;
    • Provides a mechanism for storing large amounts of data that can exist across sessions;
The storage type storage type provides the maximum storage space to store key-value pairs. Examples of storage are mainly used in the following ways:
    • GetItem (name): Gets the corresponding value based on the name specified
    • RemoveItem (name): Deletes the key-value pair specified by name
    • SetItem (name): bit specified name set a corresponding value
You can also use the Length property to determine how many key-value pairs are stored in the storage object. Localstorage object to access the same Localstorage object, the page must be from the same domain (invalid subdomain), using the same protocol, on the same window. The data stored in the Localstorage is retained until it is deleted by JavaScript or the user clears the browser cache. The storage event makes any modifications to the storage object, triggering the storage event on the document. Document.addeventlistener (' Storage ', function (evt) {}); Most desktop browsers limit localstorage to 5mb,chrome and Safari is limited to 2.5MB.

Web Data Storage Summary

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.