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
location.reload()
does in reality … but who said anything about using that method in the first place? – TorpidCache-Control
header etcetera). And the DOM for the content loaded via AJAX you will automatically get when making that AJAX request – again … so where’s the actual problem here? – Torpid// browser is not loading page automatically for back/forward
makes it even more unclear – well isn’t that why you are using the History API in the first place? If you just want the browser to load pages “normally” – then why use the History API, why use AJAX …? – Torpid