Problem:
After leaving a page that uses pushState and popState to handle back and forward navigation when retrieving HTML and JSON from the same base URL, returning to the page using the back button shows the cached JSON instead of the HTML.
Description:
- Using Ajax calls to page through search results in our application using the same URL as page URL, but with format=json.
- On each page a
window.history.pushState(state,null,url)
is called. - popState is used internally when the back and forward buttons are used within this page.
- Results have links that load other pages. (This application is not a SPA)
- After clicking on one of these links and then clicking the 'Back' button, Chrome shows the JSON stored in the state and not the previous page with a console error:
Resource interpreted as Document but transferred with MIME type application/json
Firefox and Safari correctly reload the page and since I am updating the URL in the pushState call they correctly reload the page to the state I wish (i.e. the url has the correct page identification and, therefore, reloads the correct page of the search results).