Peter Kurfer
bd27081aa6
- 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
24 lines
No EOL
613 B
JavaScript
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)
|
|
} |