HTML cache history back

2019-06-23 02:47发布

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?

2条回答
祖国的老花朵
2楼-- · 2019-06-23 03:13

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.

查看更多
Ridiculous、
3楼-- · 2019-06-23 03:13

This is browser dependent.

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

查看更多
登录 后发表回答