Reputation: 29433
I use History.js and sometimes when I click the back button I only get the content from the ajax call instead of the whole page (including the ajax call). This causes the site to look terrible as no scripts, css or html "container" is loaded.
Why is this occurring and how can I fix it?
My code looks like this:
History.Adapter.bind(window, 'statechange', function(){
var State = History.getState();
$.ajax({
url: State.url,
type: 'get',
beforeSend: function(xhr){
xhr.setRequestHeader('X-PJAX', true);
},
success: function(resp, status, xhr) {
$('#wrapper').html(resp);
}
});
});
Upvotes: 2
Views: 186
Reputation: 29433
I fixed it by disabling cache on my ajax response.
Cache-Control: no-cache, no-store, must-revalidate
Now when I click the back button the whole page is loaded instead of only the ajax response.
Upvotes: 2