I am building a webpage using web-services in Java Script. Currently, I have implemented the API and it displays the data on webpage. But, many time due to server failure data is not received and web page becomes empty.
So, I want to fetch data from API and store it locally and update those data at equal time interval. So, my application can always use locally stored data and web page never becomes empty.
How to do that, please share your views.?
As far as I can tell, you want to store data locally every time you fetch from API, so when you open the page next time, it will display last fetched data.
In that case, localStorage can be used. However, local storage should not be used for sensitive data and advanced objects. Also, it's stored as string data (JSON), so that also has some limitations.
Or sessionStorage could be an option to remove the data if the tab is closed
@OscarR sure, both extend Storage, so it really depends on the exact scenario. If he has requests polling every min, which some times updates with empty data values etc. sessionStorage might be a better approach.