Im using a web service to populate a tableview, but the data in my web database changes very rarely, and i don't need to always download the same data. I need to storage the data in the device, and verify if the data on the device is different than the one on the web. What is the best practice to do that? Parse a JSON object, containing the last version and comparing to the local version and then parsing the data if its needed ? Is there a way to automate the last version?
2 回答
I personally used local storage for the same situation on iOS and it worked great.
You just need to provide an URL which responds with the last version of the data (maybe a date) and then locally in JavaScript you first check if version online is newer than your local stored one, if it is you redownload data and place it into localstorage, otherwise you just keep old data (and don't download anything at all).
Of course everything must be done through Ajax.
If you have control over the web APIs then have a separate api that returns a timestamp for the last web data change and check this. If the date is not newer than the date of last download use the local data. imho.