ScrollX, Scroll Why? History!
Discussion of the scroll history persistence problem, and proposal for solution.
In this blog, I propose a solution to a problem facing developers in the single-page application space, especially the mobile subspace.
The challenge revolves around a pesky behavior present in all popular browser implementations. This is the automatic restoration of last scroll position upon return to each page in a browser session. If and when the user returns to a page already visisted in a session, the browser automatically triggers an uncancellable scroll event to forcibly restore that scroll position after its DOM has loaded. Likely first envisaged as a convenience, this feature has become a thorn in the side of single-page application development.
But a major shortcoming remains. The new API provides no means of preventing or overriding the automatic restoration of scroll position.
I propose a new standard that disables this behavior on a opt-out basis. In this way, it is completely backwards-compatible.
<meta name="scroll-history" content="false" />
window.history.scrollX; // e.g. 0 window.history.scrollY; // e.g. 432
What do you think? I think: W3C, get on it!