Exploring the world of AJAX-based navigation on a Rails website, with some basic jQuery hooks written in Coffeescript:
$(document).on 'click', 'a.ajax_nav', (e) ->
window.history.pushState(null, "page title", this.href)
$(window).on 'popstate', (e) ->
$.getScript(document.location)
Here's the equivalent Javascript version:
$(document).on('click', 'a.ajax_nav', function(e) {
return window.history.pushState(null, "page title", this.href);
});
$(window).on('popstate', function(e) {
return $.getScript(document.location);
});
The navigation is smooth, allowing me to use back/forward buttons and refresh the page. However, I encountered an issue when navigating using AJAX, closing the browser, and reopening it with the "restore tabs" option. The page displayed script code instead of executing it, possibly due to the cached server response being the script itself.
So my question is, can we manipulate the browser cache to force a reload? For example, setting response headers to no-cache for JS format requests. Would this trigger a reload and default to HTML rendering?
Appreciate any insights!