How to cache page loaded via ajax with pushState URL so that reloading page from server can be avoided? For instance,
page 1: /foo.html. click button, send ajax request, get response and update the page. History pushState as a new page /bar.html.
history.pushState({}, '','/bar.html');
At this point, we like the browser to cache the current page as /bar.html.
window.onpopstate = function(event) {
// browser is not loading page automatically for back/forward
if (event.state)
location.reload();
};
When clicking back/forward button, the /bar.html should be loaded from browser cache. But it is loaded from server again. How to achieve this? that is, let the ajax updated page treated as regular GET /bar.html, and cached by browser. how?
Thanks for any clue. Dave