backbone-paginator/backbone-pageable

Returning to same point in infinite when going back

dottodot opened this issue · 1 comments

I have a list of posts which I can add to using infinite scroll but if I then view a post and go back I'm returned back to the first page of posts. Can anyone suggest how I can save the current page state and on going back am returned to the same page of posts.

You basically have 2 options, one is to do nothing. The DOM state will be preserved for Firefox, Safari and IE when you click the back button. The only problem is Chrome, in which it sticks to the insane spec and just gives you back the possibly stale initial state of the last page when it was first fetched.

http://madhatted.com/2013/6/16/you-do-not-understand-browser-history

The other way to deal with it is to use local/session storage because they are not part of the HTTP cache/history mechanism. You'll have to intercept click events on links, save the scroll state and the loaded data to the storage before proceeding. The disadvantage is obviously you may potentially have to store a lot of data and you'll have to do a lot of cache validation yourself. You'll also have to polyfill this for IE6/7 which uses cookie as the actual storage. There's a 4k size limit for cookies.

http://www.sitekickr.com/blog/back-button-browser-cache/

There's no easy way out of this.