railscasts icon indicating copy to clipboard operation
railscasts copied to clipboard

back & forward navigation

Open triglav opened this issue 13 years ago • 8 comments

  1. go to http://railscasts.com, click on an episode
  2. click comments
  3. press "back" in the browser

this puts you back to the main page, instead of "show notes"

another problem appears if u now press "forward" in the browser, an AJAX reply appears without being properly handled

triglav avatar May 17 '11 12:05 triglav

Thanks for reporting! I'll get this fixed.

ryanb avatar May 17 '11 13:05 ryanb

another problem appears if u now press "forward" in the browser, an AJAX reply appears without being properly handled

Which browser are you using? Can't duplicate this in Safari.

ryanb avatar May 17 '11 13:05 ryanb

I've tried this in the latest Chrome (and Firefox as well) on winxp.

triglav avatar May 17 '11 13:05 triglav

Hmm, I'll look into fixing it. Thanks!

ryanb avatar May 17 '11 17:05 ryanb

I think this is due to the browser caching the ajax request when rendering the partial for your comments. So naturally, when you go back, it'll use the browser cache which just so happens to be the rendered partial markup code from the ajax request.

axsuul avatar Nov 01 '11 12:11 axsuul

have the same issue with Chrome 15.0.874.106 running on Ubuntu (awesome!)

suzi2000 avatar Nov 02 '11 22:11 suzi2000

I don't know is this already fixed in PJAX or not, but to prevent this you should disable caching of PJAX responses with something like this:

  # if request is from PJAX
  self.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
  self.headers['Pragma'] = 'no-cache'

By the way, I have written similar to PJAX gem, that is easier to use (from my point of view) and already has some of PJAX problems fixed: https://github.com/igor-alexandrov/wiselinks.

igor-alexandrov avatar Feb 24 '13 17:02 igor-alexandrov

Hi, yes, the problem appears when pjax is mixed with the regular browser's requests. If the URL used for both is the same google chrome will cache the last one.

The given solution though does cause the full page reload when user clicks browser's back button, thus I simply added "_pjax=#{(new Date).getTime()}" to the url I am using for the pjax request (I am not using jquery-pjax) and that worked as well.

You do not need to push that additional parameter to the history state thus it does not appear anywhere and stays invisible to users.

heaven avatar Sep 04 '13 08:09 heaven