refactor: clean up refresh script (#601)

This commit is contained in:
Kid
2022-08-08 23:19:00 +02:00
committed by GitHub
parent 6d50f4541e
commit bd45056893
+2 -2
View File
@@ -337,8 +337,8 @@ export class ServerContext {
if (this.#dev) {
routes[REFRESH_JS_URL] = () => {
const js =
`let reloading = false; const buildId = "${BUILD_ID}"; new EventSource("${ALIVE_URL}").addEventListener("message", (e) => { if (e.data !== buildId && !reloading) { reloading = true; location.reload(); } });`;
return new Response(new TextEncoder().encode(js), {
`new EventSource("${ALIVE_URL}").addEventListener("message", function listener(e) { if (e.data !== "${BUILD_ID}") { this.removeEventListener('message', listener); location.reload(); } });`;
return new Response(js, {
headers: {
"content-type": "application/javascript; charset=utf-8",
},