ryanb / railscasts

railscasts.com in open source (outdated).
http://railscasts.com
MIT License
760 stars 175 forks source link

back & forward navigation #12

Open triglav opened 13 years ago

triglav commented 13 years ago
  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

ryanb commented 13 years ago

Thanks for reporting! I'll get this fixed.

ryanb commented 13 years ago

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 13 years ago

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

ryanb commented 13 years ago

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

axsuul commented 12 years ago

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 12 years ago

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

igor-alexandrov commented 11 years ago

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 11 years ago

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.