Put hot reload code into file

This commit is contained in:
ekzyis 2023-08-25 05:15:21 +02:00
parent 754ec2988b
commit 9e112a4627
2 changed files with 17 additions and 18 deletions

View File

@ -11,23 +11,6 @@
<link rel="alternate" type="application/rss+xml" title="blog | ekzyis" href="/blog/rss.xml" />
<script defer data-api="/api/event" data-domain="ekzyis.com" src="/js/script.js"></script>
{{ if eq .Env "development" }}
<script>
const scroll = (y) => window.scrollTo(0, 925*y)
async function hotReload() {
console.log("running in development mode")
const r = await fetch("/hot-reload")
let x = await r.text()
setInterval(async () => {
const r = await fetch("/hot-reload", {
cache: "no-cache"
})
if (x !== await r.text()) {
x = r.body
window.location.reload()
}
}, 1000)
}
hotReload()
</script>
<script defer src="/hotreload.js"></script>
{{ end }}
</head>

16
public/hotreload.js Normal file
View File

@ -0,0 +1,16 @@
const scroll = (y) => window.scrollTo(0, 925*y)
async function hotReload() {
console.log("running in development mode")
const r = await fetch("/hot-reload")
let x = await r.text()
setInterval(async () => {
const r = await fetch("/hot-reload", {
cache: "no-cache"
})
if (x !== await r.text()) {
x = r.body
window.location.reload()
}
}, 1000)
}
hotReload().catch(console.error)