goveal/assets/web/js/reload.js
Peter Kurfer bd27081aa6
Add auto reload
- reload markdown if changed
- allow to monitor other files if wanted
- disable HTTP cache to force reload
- extend example
- replace almost everything with layered file systems
2020-12-04 16:40:08 +01:00

24 lines
No EOL
613 B
JavaScript

let knownHashes = {}
function getLatestHash(path) {
let request = new XMLHttpRequest()
request.open("GET", `/hash/md5${path}`)
request.onload = () => {
if(request.status === 200) {
let hashResp = JSON.parse(request.responseText)
if(path in knownHashes && knownHashes[path] !== hashResp["Hash"]) {
window.location.reload()
} else {
knownHashes[path] = hashResp["Hash"]
}
}
}
request.send()
}
function subscribeForUpdates(path) {
setInterval(() => {
getLatestHash(path)
}, 1000)
}