Dont remove(just hide) the previous data when ajax updated a page ?
In case I have a need to revisit the previous data , while updating webpages through ajax is it advisable to keep caching th开发者_StackOverflow社区e visited data in hidden tabs or hidden divs(instead of just replacing it with new data) so that when the user needs the same data, there is no need to touch the server again ?
It depends on how often it is likely to happen, and how much that extra data might effect your page.
If you user is likely to go back and forth between the data fairly often, and the hits on your server would pile up, then you might wanna keep the data on the page.
But if the data on the page has a lot of event listeners and would slow down querying for elements, then your page might run faster by not bogging down the page with all the extra data.
Unless the amount of data is really, really huge, it doesn't hurt to just keep it around. So in most cases it is advisable to just hide the old data rather than replacing it (hide it either by setting the display
style in the DOM, or by detatching the element and storing it in memory for later, the latter method usually done with the help of a framework).
In vanilla javascript, you can just apply the style element.style.display = 'none';
where element
is a reference to the DOM element you want to hide. To show it again later, you'd do element.style.display = 'block';
(assuming it is a block element -- you can also do inline
, etc... as appropriate).
精彩评论