Read this article and you can learn the following.
1.What is the use of localstorage?
2.general usage of localstorage and how to store images.
First of all, what is localstorage ?
It is a new storage technology for HTML5. But it can only store strings. This previous part of the work has been done by a cookie. However, cookies can store only about 5k of data. and Localstorage can store 5m!! This is very exciting both on the PC side and on the mobile side.
Since there is such a slight understanding. We'll probably see what it's used for.
These two days I just did a mobile project, the page is not content, but there are two big pictures. (The page is more than 200 KB) in order to improve the page loading effect, I am very eager to try the next localstorage to cache the picture.
But since Localstorage can only store strings, what's the way to make it store a picture?
At this point we can think of the format of the image can be converted, we can use canvas to do this. Next, we look at the code.
We write a function like this, we just need to define the initial img for the SRC to take the src path string as the second parameter passed into the function.
So we can set each localstorage key.
And then if we're going to take out this picture. Then we'll just use the localstorage.getitem (' key ') API to take out a bunch of base64 characters. Given to SRC, or to the URL of background. So the next time you open the page is to take out the picture directly. Isn't it cool?!
We can look at the effect of this. This also solves the F12 I used to see other people's website.
Currently the best storage localstorage