If you bind event listeners on window-load, as exemplified in your first code block, all you need to do in the refresh function is this:
<script>
function refresh() {
applicationCache.update()
}
</script>
After you have called applicationCache.update, either "updateready", "noupdate" or "error" event will fire. The error event typically means the appcache manifest could not be downloaded because the server is unreachable. You may wish to bind a listener to this event as well.
As an aside, calling window.applicationCache.swapCache()
is not necessary for how you're using appcache currently. swapCache is only needed when you want to update resources (e.g. images shown on the page) without reloading the page itself. window.location.reload()
is sufficient for a full reload of all resources, with the benefit that all your javascript is evaluated again and such. A true restart.