Reputation: 147
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:
window.history.pushState(state,null,url)
is called.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).
Upvotes: 4
Views: 1457
Reputation: 147
Looks like the answer was turning off caching of the JSON or convincing Chrome that the cached JSON wasn't what was wanted. Based on another question's answer, I added response.headers['Vary'] = 'Accept'
in the rails controller when returning JSON.
So, in context:
respond_to do |format|
format.html do
render :template => xxx
end
format.json do
response.headers['Vary'] = 'Accept'
render :json => {...}
end
end
Questions that helped me:
Upvotes: 5