javascripturlpopstate

pushState on navigating off page and back


I am trying out popstate and pushState and I am wondering how to handle off page navigation.

Lets say I have an index page which generates a 'new page' when clicking something and it's loaded in with ajax. With popstate I change the url. In the page loaded are links that go outside of the current 'index' page. When somebody presses back they get a dumped state object.

How to prevent it so it actually loads the url that was given during the pushState?

Thanks in advance.


Solution

  • It seems you're doing something that causes the browser to replace its cached version of your index page with something else. Make sure your server sets the

    Vary: Accept
    

    header when returning the index page and later requests. See this Chromium issue for more information.