Implementation of the front-end cache, in addition to the creation of JS Save (Reference: http://blog.csdn.net/clementad/article/details/46807641), you can also take advantage of the HTML5 storage method.
HTML5 provides two new objects that store data on the client:
- Localstorage: There is no time limit for data storage, in the same browser, as long as not manually cleaned, the next day, the second week or the next year after the data is still available.
- Sessionstorage: For a session of data storage, for a session for data storage. When the user closes the browser window, the data is deleted (and only valid in the current window).
The following are examples of using these two objects:
<body>
<script> $ (function () { recordvisitcount (); Recordsessioncount (); }); function Recordvisitcount () { if (localstorage.pagecount) {Localstorage.pagecount=number ( Localstorage.pagecount) +1;} else {localstorage.pagecount=1;} $ ("#visitCount"). HTML (localstorage.pagecount); } function Recordsessioncount () {if (sessionstorage.pagecount) {sessionstorage.pagecount = number ( Sessionstorage.pagecount) + 1;} else {sessionstorage.pagecount = 1;} $ ("#visitCountPerSession"). HTML (sessionstorage.pagecount);} </script>
The results of the operation are as follows:
(Original articles, reproduced please indicate the CSDN blog from Clement-xu. )
Copyright NOTICE: This article is the original article, reprint please indicate the CSDN blog which is transferred from Clement-xu.
HTML5: Local Cache