The local cache is a new technology that HTML5, and the advent of this technology has made it possible to develop mobile web. As we all know, speed is key to building a high-performance mobile application. Before HTML5, only cookies were able to store data, only 4kb in size. This severely limits the storage of application files, which can lead to a longer load time for web-developed mobile applications. With local storage, web mobile apps can be closer to native.
In the browser, local storage is called through Window.localstorage. The code that determines whether the browser supports local storage is as follows:
if (window.localstorage) {alert (' This browser supports Localstorage ');} else{alert (' This browser does not supportlocalstorage ');}
If we are going to store the data locally, the simplest way is for window. Localstorage adds a property and assigns a value to it. For example, if we want to store a data name whose value is Tom, it can be implemented in the following way:
Window.localStorage.name = "Tom"
It is important to note that string variables require quotation marks. When we want to take out the data city in local storage, we can use the GetItem method. The entire code flow is as follows:
var storage = Window.localstorage;storage.name = "Tom";//Remove the name data var name1 = Storage.getitem ("name"); alert (name1);
The result of this code in the Chrome browser console is a prompt to show Tom. It can be seen that we have correctly stored and read the data in this way.
If we want to delete these stored data, we can use the RemoveItem method. Add the following code to the above code:
Storage.removeitem ("name");
At this point we will show null when we alert again, because this data has been emptied.
HTML5 Mobile Development Practical knowledge-local storage (1)