For a time-consuming navigation (implemented in a Python/Flask backend), it's nice to have visual feedbak indicating that the next page is expected to take some time to load, even when it's just quick DIY devops scripting. To achieve this with little technical overhead I have implemented a loading message like so:
<script type="text/javascript">
function loading(){
document.getElementById("loading").style.display = 'block';
document.getElementById("content").style.display = 'none';
}
</script>
<body>
<div id="loading" class="invisible"> <!-- display: none; -->
Loading ...
</div>
<div id="content">
<a href="/time/consuming/service/call" onclick="loading();">Work miracles.</a>
(Kudos to some answers in another SO question ...)
Works like a charm in all browsers for forward navigation, but when using the browser back
button from the target page in (current) Safari or Firefox, I end up with "Loading ...",
because the display: none;
is kept when the page is reloaded from the browser cache.
In Chrome, the browser back button works fine for this case (which may raise a problem
in other use cases when the user would expect to see the page in the state they left it).
So I think I am missing something here. How can I force the back button to load cached code in the state the browser was loading the last page rather than in the state it was left?