如何使用 pushState URL 缓存通过 ajax 加载的页面,从而避免从服务器重新加载页面?例如,
第 1 页:/foo.html。单击按钮,发送 ajax 请求,获取响应并更新页面。历史 pushState 作为新页面 /bar.html。
history.pushState({}, '','/bar.html');
此时,我们喜欢浏览器将当前页面缓存为/bar.html。
window.onpopstate = function(event) {
// browser is not loading page automatically for back/forward
if (event.state)
location.reload();
};
单击后退/前进按钮时,应从浏览器缓存中加载 /bar.html。但它再次从服务器加载。如何做到这一点?也就是让ajax更新的页面被当作普通的GET /bar.html,并被浏览器缓存。如何?
感谢您提供任何线索。戴夫