HTML cache history back

依然范特西╮ 提交于 2020-01-03 12:30:10

问题


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?


回答1:


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:

History mechanisms and caches are different. In particular history
mechanisms SHOULD NOT try to show a semantically transparent view of the
current state of a resource. Rather, a history mechanism is meant to show
exactly what the user saw at the time when the resource was retrieved.

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.




回答2:


This is browser dependent.

The behavior of the history.back() button is up to the browser manufacturer.



来源:https://stackoverflow.com/questions/2695875/html-cache-history-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!