magicwallet/public/js/hotreload.js

22 lines
553 B
JavaScript

/**
* This script polls /__hotreload__ and reloads the page if the response changes.
*/
const commit = $$("commit")
console.log(`running ${commit} in development mode`)
async function fetchStatus() {
const r = await fetch("/__hotreload__", { cache: "no-cache" })
return await r.text()
}
async function hotreload() {
const status = await fetchStatus()
setInterval(async () => {
const newStatus = await fetchStatus()
if (status !== newStatus) window.location.reload()
}, 1_000)
}
hotreload().catch(console.error)