by mattkahl on 9/20/16, 11:39 PM with 49 comments
by wtbob on 9/20/16, 11:58 PM
> 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.
I don'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.
by zhoujianfu on 9/21/16, 12:08 AM
I assume this is actually a big reason people use (so many) tabs... the back button doesn't work right!
Sigh!
by jimjimjim on 9/21/16, 2:01 AM
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 important otherwise it's gonna get closed.
by panic on 9/21/16, 12:03 AM
More generally, you shouldn't make a "single-page app" 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.
by spotman on 9/21/16, 1:23 AM
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.
by mixonic on 9/21/16, 3:32 AM
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 conflict.
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 "Rob", the name auto-saves. Then you click "back".
Because single-page apps control "back" 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. This is not what the browser does. The browser, if following the "back" specs, would show the out-of-date names of Mary, Robert, and John.
The theoretical conflict can also become practical. Think through this flow:
* Visit /names
* AJAX for GET /api/names
* See Mary, Robert, John
* Edit Robert's name to Bob, autosave
* AJAX for POST /api/name/4 with the new name Bob
* See Mary, Bob, John
* Click on a link, lets say to Mary's website URL
* Mary's website, new domain, loads.
* ...click back
The SPA loads up, and attempts to GET /api/names. However, the bfcache is at play since the native "back" behavior is running. So the stale API response, with the original names Mary, Robert, John is returned. The list of names on the screen is DIFFERENT than what the user saw after they edited.
Additionally most SPA apps presume AJAX calls return accurate data, however here the names are not 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.
This is a very poorly understood corner of JavaScript development even today.
[edit]: formatting
by rosstex on 9/20/16, 11:57 PM
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).
by Manishearth on 9/21/16, 3:08 AM
The relevant spec is at https://html.spec.whatwg.org/multipage/browsers.html#the-ses...
Note:
> 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.
> 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.
and from https://html.spec.whatwg.org/multipage/browsers.html#travers...
> If entry no longer holds a Document object, then navigate the browsing context to entry's URL
and
> If entry has a different Document object than the current entry,
> ...
> Make entry's Document object the active document
------
Browsers try to treat the back button as if the user had never left the page. So the XHR requests aren't re-made because the page simply isn't reloaded, it's just made active.
The fact that Chrome says "from cache" might be a bug here, but what the devtools show isn't visible to JS/etc, so this isn'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).
I'm not clear why all of this is a problem though. If the page is reloaded, it's reloaded. If it's loaded from the bfcache, it'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?
by jlarocco on 9/21/16, 2:04 AM
For example, if I click through to the http 1.1 spec in the first paragraph, then hit "Back" I see the scrollbar shrink as new content is loaded and uBlock's block count increases as new content loads.
If I scroll to the bottom of the page, click a link, and then click back, I don't even go back to the same spot - I'm at the end of the article and content loads below it...
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 "back" display the bitmap. If going back to the page requires any network requests then the page is doing it wrong.
The exception that proves the rule would be streaming content.
by gayprogrammer on 9/21/16, 1:53 AM
The back button has not changed functionality--it still works as expected on all non-webapp webpages.
From my perspective, I think the author should be asking for browsers to implement a new button that follows his desired "load previous URL" behavior.
by eridius on 9/21/16, 12:40 AM
by rob74 on 9/21/16, 2:31 PM
by ashitlerferad on 9/21/16, 2:23 AM