How do I cache data that the page has already requested?

requirements: after the data is successfully loaded through ajax, what if the user refreshes the page and caches the requested data? Instead of requesting back-end data again. Compatible with IE8 and above


to be compatible with ie8, put it in cookie .
localstorage do not know whether it is compatible with ie8 or not, check it out for yourself.
IE9 and above are compatible.


you can store the data in localStorage or sessionStorage , and then judge that if there is data in the cache, you can directly fetch the cached data, otherwise request the data

.
if(localStorage.cacheData){
    this.data = localStorage.cacheData
}else {
    fetchData().then(res => {
        ...
    })
}

simply use cookie, 's current most compatible mode, but with a little less capacity
it's better to be in localStorage or sessionStorage if possible
if you develop app, you can write your own local files, databases, and so on.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdd166-46390.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdd166-46390.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?