breb 0.5.0

the blog/reblog library and command-line tool
Documentation
// setTimeout to avoid blocking rendering,
// which *might* happen with direct invocation but i don't trust it.
// not just adding a `loaded` event listener in case *your* scripts
// are buggy and slow and blocking things.
const { version, uniq } = document.currentScript.dataset;
setTimeout(async () => {
	const versionUrl = `${uniq}version?from=${version}`;
	const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
	while(true) {
		// thundering herd problem solution. i make perfect sense
		await sleep((Math.random() + 1) * 500);
		try {
			let resp = await fetch(versionUrl);
			if (resp.status != 200) continue;
			let newVersion = await resp.text();
			if (newVersion === version) continue;
			location.reload();
		} catch (e) {
			/* ignore e.g. the server being down */
		}
	}
}, 50);