defunkt/jquery-pjax — pull request #118 by josh (2012-04-05 01:34:19+00:00)
Title: Preserve Scroll Positions

I think this is an important feature to making pjax'd links behave closer to native full page loads. Loading a new page always scrolls you to the top and going back and forward remembers and restores you scroll position.

You'll be able to global disable it or turn it off selectively with:

``` javascript
$.pjax.defaults.preserveScrollPosition = false
```

**Implementation difficulties**

Ideally it'd be great to store `scrollPosition` along with the `pushState` state object. But we want to store the scroll position right before you navigate away, not when we changed the url. I was pretty close to coming up with something that used `replaceState` to update the current state data. That turned into a mess inside the `popstate` event since that is invoked after the url changes so theres no way to annotate the history state right before. And friggin `history.state` only works in FF not Webkit.

I ended up adding unique ids to each history state object. That way the scroll positions can be tracked separately.

/cc @defunkt