railscasts
railscasts copied to clipboard
back & forward navigation
- go to http://railscasts.com, click on an episode
- click comments
- 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
Thanks for reporting! I'll get this fixed.
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.
I've tried this in the latest Chrome (and Firefox as well) on winxp.
Hmm, I'll look into fixing it. Thanks!
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.
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.
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.