Reputation: 1175
I've a little problem in using history.js.
I try to achieve github like source browser using history.js + ajax with dojotoolkit.
It works, but I got a little problem on the server side
I use php, and when a certain page load with history.js pushState, server will first check the request type, "is it ajax?". if it's ajax, then the server will only return the requested part of the page, and if it's not the server will return full page.
The problem is, if I close the browser, and then I reopen it, the page will only show the ajax page that the server return, not the full page, because it's still known as an ajax request.
How can I solve this problem?
Upvotes: 2
Views: 296
Reputation: 437
I have had the exact same problem and spent some time researching it. Turns out when you restore a tab from history or go back to a page from a different page the original page is usually restored from browser cache (initially I thought it's making exact same request to the server, including the headers).
If your last request to a URL was AJAX and state has been pushed then the AJAX response is being cached in the browser - and later that cached response is displayed to you.
The solution for this is to disable caching of AJAX requests, by sending out proper headers. This is what I use in PHP to make sure that no browser will cache my response:
header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
Upvotes: 1