TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Browser History (2013)

109 pointsby mattkahlover 8 years ago

13 comments

wtbobover 8 years ago
I don&#x27;t get what he doesn&#x27;t understand: when the user goes back, the browser is supposed to show the document he saw when he left, as it was when he left it (so long as that view hasn&#x27;t expired out of the browser&#x27;s cache completely). This is intuitively what a user expects, right?<p>&gt; Note: if history list mechanisms unnecessarily prevent users from viewing stale resources, this will tend to force service authors to avoid using HTTP expiration controls and cache controls when they would otherwise like to. Service authors may consider it portant that users not be presented with error messages or warning messages when they use navigation controls (such as BACK) to view previously fetched resources. Even though sometimes such resources ought not to cached, or ought to expire quickly, user interface considerations may force service authors to resort to other means of preventing caching (e.g. “once-only” URLs) in order not to suffer the effects of improperly functioning history mechanisms.<p>I don&#x27;t get what he fails to understand: if the back function obeyed expiration headers, then going back could potentially reload the page, potentially causing a re-GET or even a re-POST.
评论 #12546726 未加载
评论 #12544413 未加载
zhoujianfuover 8 years ago
The way I&#x27;ve always wished the back button worked is as though I had just opened a new tab (instead of clicking a link&#x2F;submitting a form), and now I&#x27;ve just closed that tab and once again see the original tab I&#x27;d left.<p>I assume this is actually a big reason people use (so many) tabs... the back button doesn&#x27;t work right!<p>Sigh!
评论 #12544847 未加载
评论 #12545787 未加载
评论 #12545311 未加载
评论 #12544794 未加载
jimjimjimover 8 years ago
I generally want a back button that rewinds time (server side be damned).<p>usually I&#x27;ll right-mouse-button click + open in new tab on any link instead of just clicking on it.<p>Eventually, like garbage collection, I&#x27;ll stop, go back to the start of the tabs and close a bunch of them, then go back to what i was looking at.<p>And if I&#x27;m on a site that doesn&#x27;t allow right clicking on a link? well the site had better be important otherwise it&#x27;s gonna get closed.
评论 #12545131 未加载
评论 #12546673 未加载
panicover 8 years ago
You can use the pageshow event to detect when the browser navigates back in history to a page in the back&#x2F;forward cache: <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;Events&#x2F;pageshow" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;Events&#x2F;pageshow</a><p>More generally, you shouldn&#x27;t make a &quot;single-page app&quot; unless you really need to. The web is designed for navigating between multiple documents. Browser features like history and bookmarks will work better if you stick to the standard behavior.
spotmanover 8 years ago
&gt; Today, the only option for ensuring an XHR request is made when the user re-visits a page via the back button is to (1) add an unload handler then (2) use cache busting.<p>I&#x27;m sure there is exceptions, but in general, the last thing I want my browser to do when i press back, is to start making requests. I expect the requests to have been already made.
评论 #12544875 未加载
mixonicover 8 years ago
Author here, happy this popped up and to see the HN community thinking through it. A few people have brushed off what I sketched as uninteresting and don&#x27;t see any issues. I&#x27;ll try to explain it another way (with three years reflection to help).<p>Single page applications are now quite popular. <i>Most single page apps use a different definition of &quot;back&quot; than browsers do</i>, and there are times when the two treatments conflict.<p>Many, or most, use a local in-memory database to keep track of information without going to the server. They update that in-memory store as you make changes. For example you see a list of names: Mary, Robert, John. You click Robert and edit the name to &quot;Rob&quot;, the name auto-saves. Then you click &quot;back&quot;.<p>Because single-page apps control &quot;back&quot; when in the SPA, they do what most developers want. They return to a semantically correct page, showing Mary, Rob (just edited), John. Tons of apps do this. <i>This is not what the browser does</i>. The browser, if following the &quot;back&quot; specs, would show the out-of-date names of Mary, Robert, and John.<p>The theoretical conflict can also become practical. Think through this flow:<p>* Visit &#x2F;names<p>* AJAX for GET &#x2F;api&#x2F;names<p>* See Mary, Robert, John<p>* Edit Robert&#x27;s name to Bob, autosave<p>* AJAX for POST &#x2F;api&#x2F;name&#x2F;4 with the new name Bob<p>* See Mary, Bob, John<p>* Click on a link, lets say to Mary&#x27;s website URL<p>* Mary&#x27;s website, new domain, loads.<p>* ...click back<p>The SPA loads up, and attempts to GET &#x2F;api&#x2F;names. However, the bfcache is at play since the native &quot;back&quot; behavior is running. So the stale API response, with the original names Mary, Robert, John is returned. <i>The list of names on the screen is DIFFERENT than what the user saw after they edited</i>.<p>Additionally most SPA apps presume AJAX calls return accurate data, however here the names are <i>not</i> the names currently in the database. They are only in the bfcache. You can imagine, with more complex data, ways this can cause complex and unforeseen failures.<p>This is a very poorly understood corner of JavaScript development even today.<p>[edit]: formatting
评论 #12546426 未加载
评论 #12545750 未加载
评论 #12549015 未加载
rosstexover 8 years ago
On the desktop, I like having the option to see what a page just looked like, without reloading any data.<p>If I hit the back button, it&#x27;s usually because something on the previous page caught my attention and I want to find it again. If I want to reload a page, I&#x27;ll refresh or click on the site logo (in the case of getting to the root of the site).
评论 #12544387 未加载
评论 #12548842 未加载
Manishearthover 8 years ago
Note that the behavior described in the post is per spec -- the cache spec is a red herring and doesn&#x27;t apply here. The web specs override the HTTP spec in various spaces.<p>The relevant spec is at <a href="https:&#x2F;&#x2F;html.spec.whatwg.org&#x2F;multipage&#x2F;browsers.html#the-session-history-of-browsing-contexts" rel="nofollow">https:&#x2F;&#x2F;html.spec.whatwg.org&#x2F;multipage&#x2F;browsers.html#the-ses...</a><p>Note:<p>&gt; An entry with persisted user state is one that also has user-agent defined state. This specification does not specify what kind of state can be stored.<p>&gt; User agents may discard the Document objects of entries other than the current entry that are not referenced from any script, reloading the pages afresh when the user or script navigates back to such pages. This specification does not specify when user agents should discard Document objects and when they should cache them.<p>and from <a href="https:&#x2F;&#x2F;html.spec.whatwg.org&#x2F;multipage&#x2F;browsers.html#traverse-the-history" rel="nofollow">https:&#x2F;&#x2F;html.spec.whatwg.org&#x2F;multipage&#x2F;browsers.html#travers...</a><p>&gt; If entry no longer holds a Document object, then navigate the browsing context to entry&#x27;s URL<p>and<p>&gt; If entry has a different Document object than the current entry,<p>&gt; ...<p>&gt; Make entry&#x27;s Document object the active document<p>------<p>Browsers try to treat the back button as if the user had never left the page. So the XHR requests aren&#x27;t re-made because the page simply isn&#x27;t reloaded, it&#x27;s just made active.<p>The fact that Chrome says &quot;from cache&quot; might be a bug here, but what the devtools show isn&#x27;t visible to JS&#x2F;etc, so this isn&#x27;t a compatibility issue. AFAICT Chrome and Firefox (and presumably Safari) behave the same here, except from a difference in how the bfcache is invalidated. (chrome seems to invalidate when the domain changes).<p>I&#x27;m not clear why all of this is a problem though. If the page is reloaded, it&#x27;s reloaded. If it&#x27;s loaded from the bfcache, it&#x27;s as if it was never unloaded (almost the same as the user switching a tab and coming back, except of course JS was suspended). Both behaviors seem ... fine for a webapp?
jlaroccoover 8 years ago
It&#x27;s hard to take this seriously because the page itself does not work correctly w.r.t. the back button.<p>For example, if I click through to the http 1.1 spec in the first paragraph, then hit &quot;Back&quot; I see the scrollbar shrink as new content is loaded and uBlock&#x27;s block count increases as new content loads.<p>If I scroll to the bottom of the page, click a link, and then click back, I don&#x27;t even go back to the same spot - I&#x27;m at the end of the article and content loads below it...<p>My expectation as a user, regardless of the spec, is that I should see exactly what I saw when I was just on the page. Render to a bitmap, and when I click &quot;back&quot; display the bitmap. If going back to the page requires any network requests then the page is doing it wrong.<p>The exception that proves the rule would be streaming content.
gayprogrammerover 8 years ago
This isn&#x27;t an all-or-nothing issue. The author generalizes that developers and users today use browsers&#x2F;html differently than they did before, but what I&#x27;m hearing is actually a new way to use the word&#x2F;button for &quot;(go) back&quot;.<p>The back button has not changed functionality--it still works as expected on all non-webapp webpages.<p>From my perspective, I think the author should be asking for browsers to implement a new button that follows his desired &quot;load previous URL&quot; behavior.
eridiusover 8 years ago
This article no longer reflects the behavior of Safari at least as of version 10 (the version that ships with macOS Sierra). In my tests, the second version of the page that attempts to bust the bfcache behaves identically to the first version, i.e. the bfcache is not in fact busted.
rob74over 8 years ago
bendmebackmeanywayyouwantme? That rang a bell... but according to <a href="http:&#x2F;&#x2F;www.azlyrics.com&#x2F;lyrics&#x2F;garbage&#x2F;ithinkimparanoid.html" rel="nofollow">http:&#x2F;&#x2F;www.azlyrics.com&#x2F;lyrics&#x2F;garbage&#x2F;ithinkimparanoid.html</a> it should actually be bendmebreakmeanywayyouneedme ;)
ashitlerferadover 8 years ago
[2013]