HTML 缓存历史记录返回
如果我使用 history.back()
来按下按钮,会发生什么?
是否会从浏览器或缓存的本地历史记录中显示 HTML 内容,而无需浏览器向服务器请求?或者浏览器会根据浏览器历史记录中的 URL 向服务器发出请求?
If I use history.back()
for button press then what will happen?
Will the HTML content be displayed from the local history of the browser or the cache and without the browser requesting to the server? Or will the browser request to the server based on the URL that resides in history of browser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 JavaScript 中调用“history.back()”与点击浏览器用户界面中的后退按钮相同(但是,如果当前查看的位置包含框架并且这些框架已被导航,如果您比较迂腐的话,则可能会略有不同) 。
至于结果是来自服务器还是“缓存”:取决于用户代理(浏览器)。规范(RFC 2616 第 13.13 节,http://256stuff.com/gray/docs /rfc2616/13.html#13.13)说:
然而,用户代理的实现质量各不相同。例如,Mozilla/Firefox 的相关元错误可以在 https://bugzilla 找到。 mozilla.org/show_bug.cgi?id=288462
如果您尝试“返回”的页面具有合适的缓存标头,则会从缓存而不是从服务器获取该标头。
Calling "history.back()" in JavaScript is the same as hitting the back button in the browser's user interface (however, there can be slight differences if the currently viewed location contains frames and those have been navigated, if you're pedantic).
As for if the result comes from the server or "cache": it's up to the user agent (browser). The specification (RFC 2616 section 13.13, http://256stuff.com/gray/docs/rfc2616/13.html#13.13) says:
However, the user agent implementation quality differs. For example, the relevant meta bug for Mozilla/Firefox can be found at https://bugzilla.mozilla.org/show_bug.cgi?id=288462
If the page you're trying to "back" to has suitable caching headers, it will be fetched from a cache instead of from the server.
这取决于浏览器。
history.back()
按钮的行为取决于浏览器制造商。This is browser dependent.
The behavior of the
history.back()
button is up to the browser manufacturer.history.go(-1) 做同样的事情,并且在所有浏览器中都是相同的......
history.go(-1) does the very same thing and is the same across all browsers...