back & forward navigation #12

Open
triglav opened this Issue May 17, 2011 · 8 comments

Comments

Projects
None yet
6 participants

triglav commented May 17, 2011

  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

Owner

ryanb commented May 17, 2011

Thanks for reporting! I'll get this fixed.

Owner

ryanb commented May 17, 2011

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.

triglav commented May 17, 2011

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

Owner

ryanb commented May 17, 2011

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

axsuul commented Nov 1, 2011

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.

suzi2000 commented Nov 2, 2011

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

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.

heaven commented Sep 4, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment