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't see any issues. I'll try to explain it another way (with three years reflection to help). Single page applications are now quite popular. Most single page apps use a different definition of "back" than browsers do , and there are times when the two treatments conf…
What you describe does not sound like bfcache behavior. Bfcache should make it like you never clicked the link, and create no requests. Did you test this? Is something broken? Separately, do browsers currently return expired data to AJAX calls? Which ones?
Browser History (2013)
41–50 of 52 posts
Re: Browser History (2013)
#42On the desktop, I like having the option to see what a page just looked like, without reloading any data. If I hit the back button, it'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'll refresh or click on the site logo (in the case of getting to the root of the site).
Re: Browser History (2013)
#43I don't get what he doesn'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't expired out of the browser's cache completely). This is intuitively what a user expects, right? > Note: if history list mechanisms unnecessarily prevent users from viewing stale resources, this will tend to force service authors to av…
As I read and see this, it is not about normal HTML pages. The issue probably is more important for SPAs. For example, you post something that increases your total message counter, and the URL is changed (single page app: the page is not reloaded, only modified by Javascript), for example showing the new message (think "forum" as an example). If the user clicks "Back" they may get the page-state with the previous cou…
But really, one should avoid SPAs like the plague. Write web sites consisting of web pages. Only if the site or pages need more should one add JavaScript, and only if it's insufficient to purpose should one write an SPA (as an example, I have a hard time envisioning Mattermost, IRC or Slack working as web pages).
Re: Browser History (2013)
#44> 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. I'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.
The result of this thinking is when I press the back button, I have to refresh the page manually because the data is stale. My daily use case for this is Github Issues. Simple repro: Click an issue, make a change, press back. Now the list view is out of date and doesn't show my changes. So I have to refresh. I think a background XHR request is the best approach (until browsers fix this issue for real). On page load:…
Okay. C-r is quick and easy to type. But if Back automatically destroys the old version of the page, then there is no way to restore that old page.
> My daily use case for this is Github Issues. Simple repro: Click an issue, make a change, press back.
> Now the list view is out of date and doesn't show my changes. So I have to refresh.
How is that different from one tab with the list of issues, and one tab with a specific issue? In the tab instance, GitHub has added JavaScript to the issue list page to refresh on changes; in the Back button instance, it should work identically: the list view is 'rehydrated,' the JavaScript does its thing and the list view is updated.
Reloading the page is completely, totally wrong.
Re: Browser History (2013)
#45Author 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't see any issues. I'll try to explain it another way (with three years reflection to help). Single page applications are now quite popular. Most single page apps use a different definition of "back" than browsers do , and there are times when the two treatments conf…
That's because SPAs are, at heart, an abuse of the Web and of the power Web browsers offer. They are to the Web what a text editor written in Brainf*ck would be: an abuse of extensibility, rather than of Turing completeness.
Re: Browser History (2013)
#46Earlier quoted context omitted.
As I read and see this, it is not about normal HTML pages. The issue probably is more important for SPAs. For example, you post something that increases your total message counter, and the URL is changed (single page app: the page is not reloaded, only modified by Javascript), for example showing the new message (think "forum" as an example). If the user clicks "Back" they may get the page-state with the previous cou…
I would expect that if one must write a SPA then one will hijack the Back button, no? So one could implement whatever logic makes sense within the SPA. But really, one should avoid SPAs like the plague. Write web sites consisting of web pages. Only if the site or pages need more should one add JavaScript, and only if it's insufficient to purpose should one write an SPA (as an example, I have a hard time envisioning M…
> one should avoid SPAs like the plague
Why? I don't see any basis for such a statement, but I'm more than willing to learn.Re: Browser History (2013)
#47I generally want a back button that rewinds time (server side be damned). usually I'll right-mouse-button click + open in new tab on any link instead of just clicking on it. Eventually, like garbage collection, I'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. And if I'm on a site that doesn't allow right clicking on a link? well the site had better be impor…
Use middle click (or for those without a middle mouse button on a computer they can't reconfigure, use ctrl/cmd + click)
But more importantly, you can't use either method if the link is a javascript function.
Re: Browser History (2013)
#48Earlier quoted context omitted.
I would expect that if one must write a SPA then one will hijack the Back button, no? So one could implement whatever logic makes sense within the SPA. But really, one should avoid SPAs like the plague. Write web sites consisting of web pages. Only if the site or pages need more should one add JavaScript, and only if it's insufficient to purpose should one write an SPA (as an example, I have a hard time envisioning M…
> one should avoid SPAs like the plague Why? I don't see any basis for such a statement, but I'm more than willing to learn.
The Web is supposed to be about resources and links between them; that's what REST is about (in a very real sense, REST is the driving principle behind the Web). In pretty much every case, those resources can have an attractive, human-readable HTML representation (but they may of course also have easily-parsed JSON or high-performance Thrift, flatpack or protobuf representations). One should be able to use a browser as one's user agent to use a web site built on REST principles to perform any sequence of operations that web site makes available.
Now, one might provide quite a lot of JavaScript over top of that REST interface, in order to provide a more user-friendly experience (one could imagine HN using JavaScript to allow inline commenting, while still preserving the ability to POST). In general, one should provide the plain resource-oriented interface first, and only add JavaScript later. For one thing, this helps one think clearly about the API; for another, it's a lot easier to take a clean REST API and use it from JavaScript than it is to take a purpose-built SPA and try to turn it into a proper REST system.
Now, there do exist some systems which really, really don't make a lot of sense as primarily REST apps — in my post, I used the example of chat apps. Certainly, they should have REST APIs, but honestly I can't see most people wanting to use them that way (although … it may be convenient in order to avoid distraction). For that sort of app, it's conceivable that one might properly begin with the SPA. Another example might be the 2048 game, or similar things. As much as I'd prefer a native gtk+ game, it is true that most people haven't yet upgraded to Linux; it's also true that as terrible as the JavaScript privacy & security stories are, they are much better than the native app privacy & security stories.
All those are good reasons to write an SPA.
But if one is building a brochure site, or a blog, or a magazine, or a trip planner, or an e-commerce site, or pretty much anything that most of use — then starting with an SPA is wrong. All of those should be modeled as resources and state first, with UI added later.
An example would be that I discovered it's impossible to checkout using Target's website without JavaScript; I was just trying to send a gift certificate to a friend, and now Target isn't seeing that money, due to a poor design decision. There's absolutely no reason that Target should require me to enable JavaScript in order to POST them a credit card number and a quantity.
Re: Browser History (2013)
#49Earlier quoted context omitted.
> So the stale API response, with the original names Mary, Robert, John is returned. This seems like a bug -- if you click back, it should take you to the page you saw before, not an earlier version of it. AIUI the bfcache doesn't "remember and replay" API requests; it just caches the entire DOM and JS state. Do you have something that can demonstrate this behavior? > Because single-page apps control "back" when in t…
Sorry :-( You are correct. What I described is not be behavior of the bfcache, it is the network behavior described under the heading "In practice". And there is a link there to a server that can help you play with the behavior. Apologies for using the wrong term and causing confusion. > This is not necessarily what users want (as evidenced by discussions on this post). HN not being representative of an average user…
Right, except requests aren't being made there, it's just that the devtools seem to say that they are. The scenario you gave as an example (with the /names API call and whatnot) isn't possible AFAICT. Maybe I misread something?
> My point is that there are two different expectations
Yeah, agreed, there are two expectations here.
APIs that let you explicitly invalidate bfcache entries (something on pushState() maybe?) or detect bfcache loads would be interesting, and would let SPAs deal with this problem, perhaps.
Re: Browser History (2013)
#50Earlier quoted context omitted.
> one should avoid SPAs like the plague Why? I don't see any basis for such a statement, but I'm more than willing to learn.
SPAs are basically an exploit, taking advantage of a dynamic document model and a language intended to layer a little bit of behaviour atop that model, and using it instead to deliver entire applications. It's a little like noticing that sed is Turing complete, and thus writing a text editor in sed. The Web is supposed to be about resources and links between them; that's what REST is about (in a very real sense, REST…